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('你输了')
  • 相关阅读:
    css 水平垂直居中总结
    计算机网络之应用层详解
    WPF 中 InitializeComponent 不存在解决方案
    [翻译]lithium 快速上手(QuickStart)
    [翻译]lithium 安装
    [翻译]lithium介绍
    [模板]离散化
    [总结]中位数及带权中位数问题
    [总结]Floyd算法及其应用
    [模板]SPFA判负环
  • 原文地址:https://www.cnblogs.com/shen-qiang/p/8563496.html
Copyright © 2011-2022 走看看