Python(4)编写程序,求出最小的100个素数。要求每行输出10个数,输出效果如图3.
1个回答
关注
展开全部
1.```pythonnum = int(input("请输入门票数量:"))if num = 5 and num <= 20: price = num * 90 # 九折else: price = num * 80 # 八折print("总票价为:", price, "元")```2.```pythonyear = int(input("请输入年份:"))if (year%4==0 and year%100!=0) or year%400==0: print(year, "年是闰年")else: print(year, "年不是闰年")```3.```pythonfor i in range(1, 1000): if str(i) == str(i)[::-1]: print(i)```4.```pythoncount = 0 # 记录素数的数量i = 2 # 从2开始判断是否为
咨询记录 · 回答于2023-03-28
Python(4)编写程序,求出最小的100个素数。要求每行输出10个数,输出效果如图3.
你好能不能详细说下
(4)
1.```pythonnum = int(input("请输入门票数量:"))if num = 5 and num <= 20: price = num * 90 # 九折else: price = num * 80 # 八折print("总票价为:", price, "元")```2.```pythonyear = int(input("请输入年份:"))if (year%4==0 and year%100!=0) or year%400==0: print(year, "年是闰年")else: print(year, "年不是闰年")```3.```pythonfor i in range(1, 1000): if str(i) == str(i)[::-1]: print(i)```4.```pythoncount = 0 # 记录素数的数量i = 2 # 从2开始判断是否为
素数
if i % j == 0: is_prime = False break if is_prime: # 如果是素数,输出 print(i, end='\t') count += 1 if count % 10 == 0: # 每10个素数输出一个换行符 print() i += 1```