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('你输了')
  • 相关阅读:
    notification(浏览器通知)
    面试的信心来源于过硬的基础
    碰撞检测
    使用自定义的鼠标图标 --- cursor url
    js中json字符串转成js对象
    【php学习】字符串操作
    Car的旅行路线(codevs 1041)
    Find them, Catch them(poj 1703)
    Period(poj 1961)
    Power Strings(poj 2406)
  • 原文地址:https://www.cnblogs.com/shen-qiang/p/8563496.html
Copyright © 2011-2022 走看看