zoukankan      html  css  js  c++  java
  • GUI-猜字游戏

    # 设计思想先定义输入,输入,然后设计逻辑
    # GUI from tkinter
    # 逻辑层
    # 设计GUI(用户界面)
    from tkinter import *
    import tkinter.simpledialog as dl
    import tkinter.messagebox as  md
    root = Tk()
    w = Label(root, text='Guess Number Game')
    w.pack()
    
    md.showinfo('welcome','welcome to Guess Number Game')
    # guess = dl.askinteger('number', 'Enter a number')
    number = 59
    
    while True:
        guess = dl.askinteger('Number', "what's your guess?")
        if guess == number:
            output = 'Bingo! you guess it right,but you do not win any prizes'
            md.showinfo('Hint:' ,output)
            break
        elif guess < number:
            output = 'No,the number is a higher than that'
            md.showinfo('Hint:', output)
        else:
            output = 'No, the number is a lower than that'
            md.showinfo('Hint:', output)
    print('Done')
    
    output = 'this is output message'
    md.showinfo('output',output)

    这里提供另一种方法:

    import random
    # random.randint(-1,10) #-1,0,1,2,3,4,5,6,7,8,9,10
    computer = random.randint(0,2)
    #站在用户的角度上
    # 用户赢
    # 0-->2  1-->0  2-->1
    # 用户和电脑打平0
    # 0-->0 1-->1 2-->2
    # 用户输
    # 除了上面所有的情况,都是输
    
    if (person == 0 and computer == 2)or(person == 1 and computer == 0)or(person == 2 and computer == 1):
        print('你赢了')
    elif  person == computer:
        print('平手')
    else:
        print('你输了')
  • 相关阅读:
    idea 配置 maven 项目
    idea 配置普通web项目
    idea java.lang.OutOfMemoryError: PermGen space
    idea checkout 项目
    物理机自动化装机实现
    prometheus node_exporter相关监控指标
    nginx Linux内核参数的优化
    《高性能 Go 代码工坊》中译
    docker仓库资源的地址修改
    influxdb-1.7.8(centos 7) 部署
  • 原文地址:https://www.cnblogs.com/shen-qiang/p/8563496.html
Copyright © 2011-2022 走看看