代碼
year=int(input("請輸入年份:"))
if(year%4 == 0 and year%100 != 0):
print("閏年")
elif(year%400 == 0):
print("閏年")
else:
print("不是閏年")
運行結果
代碼
a=float(input("a="))
b=float(input("b="))
c=float(input("c="))
if a>b and a>c :
print("最大值為:a")
elif b>c :
print("最大值為:b")
else:
print("最大值為:c")
運行
代碼
def f(n):
if n > 10 or n < 1:
return 0
elif n == 10:
return 1
else:
return 2 * (f(n+1)+1)
print(f(1))
運行結果
代碼
s=input("請輸入字符:")
upper=0 #大寫字母
lower=0 #小寫字母
space=0 #空格
digit=0 #數字
other=0 #其他
for i in s:
if i.isupper():
upper += 1
elif i.islower():
lower += 1
elif i.isspace():
space += 1
elif i.isdigit():
digit += 1
else:
other += 1
print("大寫字母{},小寫字母{},空格{},數字{},其他字符{}".format(upper,lower,space,digit,other))
運行結果
代碼
n=int(input("請輸入一個數:"))
print(n , end ="")
i = 2
s = ""
while i <= 1000 :
if n % i == 0:
s += str(i)
n = int(n/i)
continue
i += 1
print(" = {}".format("*".join(s)))
運行結果
代碼
import random
n1 = [chr(i) for i in range(65,90)]
n2 = [i for i in range(1,10)]
n=n1+n2
for i in range(20):
for j in range(6):
print(random.choice(n),end="")
print()
運行結果
代碼
score = float(input("請輸入你的成績:"))
if 90 <= score <= 100:
print("優秀")
elif 80 <= score <= 89:
print("良好")
elif 70 <= score <=79:
print("中等")
elif 60 <= score <= 69:
print("及格")
else:
print("不及格")
運行結果
代碼
nums = tuple(map(int, input("please input numbers:").split(',')))
def sum_nums(nums):
sum=0
for i in nums:
sum += i
return sum
print(sum_nums(nums))
運行結果