avatar

pyhon入门小结
  • 2019.10.4
      在宿舍太闲想着复习下前面的知识,就花了大半天做了一个基础的复习.太怠慢了.
    import time
    import linecache
    import random
    import os
    def main():
      while True:
          try:
              print("- -" * 20)
              # 一言
              file_yi = r'E:\python\book\yi.txt'
              num_yi = random.randint(1, 300)
              def line(file, num):
                  a = linecache.getline(file, num).strip()
                  print("当前时间:", end='')
                  print(time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time())))
                  print("- -" * 20)
                  print("一言:  " + a)
              line(file_yi, num_yi)
    
    
        print("- -" * 20)
        print("1.手机充值\n"
              "2.根据父母身高预测儿子身高\n"
              "3.根据总步数计算消耗的热量\n"
              "4.猜谜语\n"
              "5.逢七拍腿\n"
              "6.清屏\n"
              "0.退出程序")
        print("- -" * 20)
        choose =int(input("输入你的选择:"))
        print("你选择了:%d"%choose)
        if choose in [1,2,3,4,5,6,7,0]:
            if choose ==1:
                mobile()
            elif choose ==2:
                height()
            elif choose ==3:
                heat()
            elif choose ==4:
                riddle()
            elif choose ==5:
                number_7()
            elif choose ==6:
                os.system('color a')
                os.system('cls')
            elif choose ==7:
                os.system('color a')
                os.system('cls')
                print("* * * * *启动里模式* * * * *")
                os.system('E:\python\\book\\123.bat')
            elif choose ==0:
                print("退出成功")
                break
            else:
                print("输入错误,重新输入")
    except ValueError:
        print("输入错误重新输入")
    except Exception as c:
        print("未知错误%s" % c)

#1.手机充值
def mobile():
of = float(input(“输入充值金额:”))
print(“您以成功充值%.2f元”%of)
#2.根据父母身高预测儿子身高
def height():
fheight =float(input(“父亲身高(cm):”))
mheight =float(input(“母亲身高(cm):”))
eheight =(fheight+mheight)0.54
print(“预测儿子身高为:%.2f(cm)”%eheight)
#3.根据总步数计算消耗的热量
def heat():
count =int(input(“输入步数:”))
calories =count
28
kcalories =count*28/100
print(“今天走了%d步\n”
“消耗%d卡路里\n”
“(%d千卡)”%(count,calories,kcalories))
#4.猜谜语
def riddle():
while True:
print(“今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问几何?”)
number = int(input(“输入谜底:”))
if number%3 ==2 and number%5 ==3 and number%7 ==2:
print(“你输入:%d,\n恭喜答对了\n”%number)
break
elif number>100:
print(“- - - - 开启自助解答模式 - - - -“)
for number in range(101):
print(“正在尝试第%d次”%number)
if number % 3 == 2 and number % 5 == 3 and number % 7 == 2:
print(“你输入:%d,\n恭喜答对了\n” % number)
print(“- - - - 自助解答模式结束 - - - -“)
break
else:
print(“你输入:%d,\n很遗憾请再接再厉\n”%number)
#5.逢七拍腿
def number_7():
numlist = []
number = int(input(“输入你想要计算的个数:”))
for number in range(number+1):
if number%7 ==0 and number !=0:
numlist.append(number)
elif str(number).endswith(“7”):
numlist.append(number)
print(“在这%d个数中被七和末尾是七的数一共有%d个”%(number,len(numlist)))
print(“以下数字是被七和末尾是七的数:\n%s”%numlist)
if name == ‘main‘:
main()
#number_7()

文章作者: wangzun233
文章链接: https://wangzun233.top/2019/10/04/pyhon%E5%85%A5%E9%97%A8%E5%B0%8F%E7%BB%93/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 WangZun233