美文网首页
Python网上6小时教程 笔记代码

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

作者: 听歌的芝麻 | 来源:发表于2020-02-09 17:22 被阅读0次

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')

相关文章

网友评论

      本文标题:Python网上6小时教程 笔记代码

      本文链接:https://www.haomeiwen.com/subject/nmrnxhtx.html