Python网上6小时教程 笔记代码

B站 Youtube 光头教程
[https://www.bilibili.com/video/av75855831]

猜数字小游戏
猜0-99之间的数字,每人有5次机会。

import random
x = random.randint(0,10)

i = 0
while i<5:
    y = int(input('请输入猜测的数字:'))
    i = i + 1
    if y<x:
        print('低了')
    elif y>x:
        print('高了')
    else:
        print('恭喜猜中!')
        break

else:
    print('已使用完五次机会,游戏结束。')
    print(f'随机数为{x}')

开车小游戏

command = ''
car = False
while True:
    command = input('> ').lower()
    if command == 'start':
        if car:
            print('已经在开了')
        else:
            car = True
            print('car started...')
    elif command == 'stop':
        if not car:
            print('车已经停了')
        else:
            car = False
            print('car stopped')
    elif command == 'quit':
        break
    elif command == 'help':
        print('''
start,
stop,
quit
        ''')
    else:
        print('i dont know')
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容