python基础入门(练习题)

目录

  • 前言
  • 附录

前言

本次内容主要围绕之前介绍的内容和方法,列举出相应练习题,在附录上面有相应的代码。当然这些代码还可以进一步进行优化,有想法的朋友,可以私信发给我更好更完善的代码。


附录

成绩判断.py
grade = int(input("你的考试成绩:"))

if grade < 100:
    if grade > 0:
        print("你输入的成绩有效")
    else:
        print("你输入的成绩无效")
else:
    print("你输入的成绩无效")

if grade > 90:
    print("你是A类")
elif 80 < grade < 90:
    print("你是B类")
elif 70 < grade < 80:
    print("你是C类")
elif 60 < grade < 70:
    print("你是D类")
else:
    print("你不及格")

给出数字求和_for.py

n = int(input('How many numbers to sum?'))
total = 0
for i in range(n):
    s = input('Enter number '+ str(i+1) +': ')
    total += int(s)
print('The sum is '+str(total))

给出数字求和_while.py

n = int(input('How many numbers to sum?'))
total = 0
i = 1
while i <= n:
    s =input('Enter number '+ str(i) +': ')
    total += int(s)
    i += 1
print('The sum is '+str(total))

九九乘法表.py

for row in range(1,10):
    for col in range(1,10):
        prod = row * col        
        if prod < 10:
            print(' ',end='')            
        print(row * col,' ',end='')
    print()

九九乘法表_改进.py

for row in range(1,10):
    for col in range(1,row+1):
        prod = row * col        
        if prod < 10:
            print(' ',end='')            
        print(row * col,' ',end='')
    print()

1到100奇数和.py

s = 0
for i in range(1,101,2):
    s = s+i
print("sum=",s)

1到100偶数和.py

s = 0
for i in range(2,101,2):
    s = s+i
print("sum=",s)

求阶乘_for.py

fact = 1
n = int(input('请输入要求的整数的阶乘:'))
if n > 0:
    print("输入正确正在计算")
elif n == 0:
    print('阶乘是'+str(fact))
else:
    print("输入有误请重新输入")
while n < 0:
    break
for i in range(2,n+1):
    fact = fact * i
print(str(n)+'阶乘是'+str(fact))

求阶乘_while.py

n = int(input('请输入要求数的阶乘:'))
fact = 1
i = 2
while i <= n:
    fact = fact * i
    i = i + 1
print(str(n)+'阶乘是'+str(fact))

未知个数数字求和.py

s = int(input('Enter a number (or "done"): '))
total = 0
while s != 'done':
    num = int(s)
    total += num
    s = (input('Enter a number (or "done"): '))
print('The sum is ' + str(total))
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

转瞬都有

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值