赞
踩
a=0,b=1
#斐波拉契数列
a,b=0,1
while b<10:
print(b,end=" ")
a,b=b,a+b
#1 1 2 3 5 8
a=1
while a<7:
if a % 2 == 0:
print(a,"is even")
else:
print(a, "is odd")
a += 1
# 1 is odd
# 2 is even
# 3 is odd
# 4 is even
# 5 is odd
# 6 is even
age = int(input('请输入狗狗的年龄:'))
if age <= 0:
print('狗狗年龄怎么会小于0的喔')
elif age == 1:
print('相当于14岁的人')
elif age == 2 :
print('相当于22岁的人')
elif age > 2 :
human = 22 + (age-2)*5
print('狗狗的年龄相当于',human,'岁')
# 请输入狗狗的年龄:3
# 狗狗的年龄相当于 27 岁
num=int(input("请输入你心目中的数字:"))
if num % 2 == 0:
if num % 3 ==0:
print('你的数字可以被2,3整除')
else:
print('你的数字可以被2整除,但是不能被3整除')
else :
if num % 3 == 0:
print('你的数字能被3整除,但不能被2整除')
else :
print('你的数不能被2或3整除')
# 请输入你心目中的数字:65874682
# 你的数字可以被2整除,但是不能被3整除
begin = float(input('起点:'))
begin0 = begin
n=float(input("终点:"))
step=float(input('间隔:'))
sumvalue = 0
while begin <= n:
sumvalue = begin + sumvalue
begin += step
print("%d到%d的步长为%d的和为:%d"%(begin0,n,step,sumvalue))
# 起点:1
# 终点:11
# 间隔:2
# 1到11的步长为2的和为:36
#for循环计算阶乘
n = int(input("please input your integer>=0:"))
result = 1
for i in range(2,n+1):
result = result * i
print(str(n) + ' factorial is ' + str(result) )
#while循环计算阶乘
n=int(input('please input your integer >= 0'))
i=1
result=2
while i<=n:
result = result * i
i += 1
print(str(n) + " factorial is " + str(result))
#for 计算输入数字的和 n = int(input("how many numbers to sum?")) total = 0 for i in range(n): s = input('The number '+ str(i+1) + " is :") total = total + int(s) print("The sum is " + str(total)) #while 计算输入数字的和 n = int(input("how many numbers to sum? ")) i = 1 result = 0 while i <= n: s = input("The number " + str(i) + " is :") i += 1 result = result + int(s) print('The sum is '+ str(result))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。