python基础试题

2021-01-02 22:27

阅读:439

标签:inpu   pytho   python   用户输入   put   pen   一个   app   试题   

‘‘‘
打印三角行;------------
lines = int(input(‘请输入行数:‘))
for i in range(lines):
for j in range(i):
print("*",end= ‘ ‘)
print()

‘‘‘

‘‘‘
打印倒立三角行;
lines = int(input(‘请输入行数:‘))

for i in range(lines):
j = 0
while j print("*",end= ‘ ‘)
j += 1
print()
‘‘‘

# 打印九九乘法表---------------------
‘‘‘
i = 1
while i j = 1
while j print(‘%d * %d = %d‘ %(j,i,j*i),end= ‘ ‘)
j += 1
i += 1
print()
‘‘‘

# # 求1000以内的水仙花数--------------------
‘‘‘
for i in range(100,1000):
m = i // 100
n = i // 10 % 10
p = i % 10
if (m ** 3) + (n ** 3) +(p ** 3) == i:
print(i,end=‘,‘)
‘‘‘

# 求1-100以内所有偶数的和------------------
‘‘‘
sum = 0
i = 1
while i if i % 2 == 0:
sum += i
i += 1
print(sum)


# 获取用户输入的任意数,判断其是否是质数?-----------------
num1 = int(input(‘请输入一个整数‘))
i = 2
while i if num1 % i == 0:
print(num1,"不是质数")
print(i,"*",num1//i,"是",num1)
break
i += 1
else:
print(num1,"是质数")


‘‘‘

# n = int(input("请输入一个数字:")) # ------------

‘‘‘
j = 2
while j if n % j == 0:
print(n,‘不是质数‘)
print(j,"*",n//j,‘是‘,n)
break
j += 1
else:
print(n,"是质数")

‘‘‘

# 打印出100 以内的质数 ------------------
‘‘‘
num = []
j = 2
for i in range(2,100):
for j in range(2,i):
if i % j == 0:
break
else:
num.append(i)
print(num)

‘‘‘














python基础试题

标签:inpu   pytho   python   用户输入   put   pen   一个   app   试题   

原文地址:https://www.cnblogs.com/zhansheng/p/12993670.html


评论


亲,登录后才可以留言!