猫史档案馆


【Python作品分享】猜数字【作品秀】

用户:ZCH_ProZCH_Pro查看:54 回复:6 评论:54 创建时间:2020-03-07T12:44:27


【作品展示】

center_image

 

【作品介绍】

猜数字······

无聊时可以玩玩·····

我天天玩这个······

嘿嘿······

一脸滑稽······

 

【作品源代码】

import random


#猜数字游戏

number = random.randint(1, 100)
guess = 0
while (guess != number):
    guess = int(input('猜一个我正在想的数字是什么,嘿嘿~ (1-100之间)'))
    if (guess > number):
        print(guess,'太大了,同志,再试一次吧')
    if (guess < number):
        print(guess,'太小了,同志,再试一次吧')
print('猜对了,你还挺厉害的嘛')

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
cool-creepercool-creeper

呵呵,我有超级加强版,注意!超级!哼,一前说我小气的,我把源代码都奉上了!

#导入随机、界面、海龟和系统模块
import random
import easygui
import turtle
import sys
import time
#检测系统
try:
    assert ('linux' in sys.platform)
    system = 'Linux'
except AssertionError:
    try:
        assert ('win' in sys.platform)
        system = 'Windows'
    except AssertionError:
        system = 'MacOS'
easygui.msgbox('欢迎来到猜数字V2.1 for'+system,'欢迎','好')
#随机数
number = random.randint(1, 100)
#增加计数变量
times = 0
#增加最大和最小值变量
Maximum_value = 100
Minimum_value = 1
#询问数字,将结果存放在变量guess中
guess = turtle.numinput('输入数字', '请输入一个范围为'+str(Minimum_value) +'至'+str(Maximum_value)+'的数', '', Minimum_value, Maximum_value)
clock = time.ctime()
while (number != guess):
    #判断
    if guess > number:
        Maximum_value = int(guess)
        #显示猜大了的界面提示
        easygui.msgbox('猜大啦~', '猜大啦~', '好')
    else:
        #显示猜小了的界面提示
        Minimum_value = int(guess)
        easygui.msgbox('猜小啦~', '猜小啦~', '好')
    guess = turtle.numinput( '继续猜', '请输入一个范围为'+str(Minimum_value)+'至'+str(Maximum_value)+'的数', '', Minimum_value, Maximum_value)
    times += 1
#显示成绩
easygui.msgbox('猜对啦!你一共猜了'+str(times+1)+'次', '猜对啦!')
#询问是否要保存成绩
question = easygui.ynbox('需要保存当前成绩吗?','保存当前成绩',('好的','不,谢谢'))
#如果玩家想保存,执行以下操作
if question == True:
    #如果系统为Windows,执行以下操作
    if system == 'Windows':
        #打开一个新的.txt文件,将文件命名为本局成绩.txt,放在D盘里
        file = open('D:\本局成绩.txt','w',encoding = 'utf-8')#设置引擎为utf-8(识别中文)
        #往本局成绩.txt里填写内容
        file.write('本局成绩:一共猜了'+str(times)+'次。时间:'+clock)
        file.close()
        #通知玩家已保存
        easygui.msgbox('成绩已保存在D盘,感谢您的游玩')
    #否则如果系统为MacOS,执行以下操作
    elif system == 'MacOS':
        #打开一个新的.txt文件,将文件命名为本局成绩.txt,放在user文件里
        file = open('/user/本局成绩.txt','w',encoding = 'utf-8')
        #往本局成绩.txt里填写内容
        file.write('本局成绩:一共猜了'+str(times)+'次。时间:'+clock)
        file.close()
        #通知玩家已保存
        easygui.msgbox('成绩已保存在user文件夹,感谢您的游玩')
    #否则系统一定为Linux,通知玩家Linux系统不支持保存成绩
    else:
        easygui.msgbox('抱歉,猜数字V2.1暂时不支持在Linux系统中保存当前成绩,请等待作者更新。')
        easygui.msgbox('感谢您的游玩')
#否则告诉玩家感谢您的游玩
else:
    easygui.msgbox('感谢您的游玩')

点赞0


评论


ZCH_ProZCH_Pro

#第一个程序。主程序
import sys
from PySide2.QtWidgets import*
from PySide2.QtGui import*
from ui_process_img import Ui_MainWindow
from PIL import Image,ImageFilter,ImageQt


class ProcessImg(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.file = None

        self.filters = {
                        "模糊滤镜": ImageFilter.BLUR,
                        "轮廓滤镜":ImageFilter.CONTOUR,
                        "边缘增强滤镜": ImageFilter.EDGE_ENHANCE,
                        "浮雕滤镜":ImageFilter.EMBOSS,
                        "锐化滤镜":ImageFilter.SHARPEN,
                        "平滑滤镜":ImageFilter.SMOOTH,
                                                    }

        self.pbtn_file.clicked.connect(self.select_file)
        self.pbtn_process.clicked.connect(self.process_img)

        self.lb_input_img.setScaledContents(True)
        self.lb_output_img.setScaledContents(True)

        self.show()

    def select_file(self):
        file_path = QFileDialog.getOpenFileName(caption="选择文件",filter="(* .jpg * .png)")
        if file_path[0]:
            self.file = file_path[0]
            img_pix = QPixmap(self.file)
            self.lb_input_img.setPixmap(img_pix)
        else:
            QMessageBox.warning(self, "注意", "请先选择图片文件呀~TAT~")

    def process_img(self):
        if self.file:
            img = Image.open(self.file)
            text = self.cb_filter_list.currentText()
            img_temp = img.filter(self.filters[text]).convert("RGBA")
            img_qt = ImageQt.ImageQt(img_temp)
            img_pix = QPixmap.fromImage(img_qt)
            self.lb_output_img.setPixmap(img_pix)
        else:
            QMessageBox.warning(self,"注意","请先选择图片文件呀~TAT~")

if __name__=="__main__":
    app = QApplication(sys.argv)
    window = ProcessImg()
    sys.exit(app.exec_())







# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'C:/Users/Apple/Desktop/filter/process_img.ui',
# licensing of 'C:/Users/Apple/Desktop/filter/process_img.ui' applies.
#
# Created: Mon Feb 17 20:26:32 2020
#      by: pyside2-uic  running on PySide2 5.12.3
#
# WARNING! All changes made in this file will be lost!
#第二个程序,副程序
from PySide2 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(655, 417)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setContentsMargins(-1, -1, -1, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.pbtn_file = QtWidgets.QPushButton(self.centralwidget)
        self.pbtn_file.setMinimumSize(QtCore.QSize(0, 0))
        self.pbtn_file.setMaximumSize(QtCore.QSize(16777215, 50))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.pbtn_file.setFont(font)
        self.pbtn_file.setObjectName("pbtn_file")
        self.horizontalLayout.a喵Widget(self.pbtn_file)
        self.cb_filter_list = QtWidgets.QComboBox(self.centralwidget)
        self.cb_filter_list.setMinimumSize(QtCore.QSize(250, 0))
        self.cb_filter_list.setMaximumSize(QtCore.QSize(16777215, 50))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.cb_filter_list.setFont(font)
        self.cb_filter_list.setObjectName("cb_filter_list")
        self.cb_filter_list.a喵Item("")
        self.cb_filter_list.a喵Item("")
        self.cb_filter_list.a喵Item("")
        self.cb_filter_list.a喵Item("")
        self.cb_filter_list.a喵Item("")
        self.cb_filter_list.a喵Item("")
        self.horizontalLayout.a喵Widget(self.cb_filter_list)
        self.pbtn_process = QtWidgets.QPushButton(self.centralwidget)
        self.pbtn_process.setMaximumSize(QtCore.QSize(16777215, 50))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.pbtn_process.setFont(font)
        self.pbtn_process.setObjectName("pbtn_process")
        self.horizontalLayout.a喵Widget(self.pbtn_process)
        self.verticalLayout.a喵Layout(self.horizontalLayout)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.lb_input_img = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(30)
        self.lb_input_img.setFont(font)
        self.lb_input_img.setAlignment(QtCore.Qt.AlignCenter)
        self.lb_input_img.setObjectName("lb_input_img")
        self.horizontalLayout_2.a喵Widget(self.lb_input_img)
        self.lb_output_img = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(30)
        self.lb_output_img.setFont(font)
        self.lb_output_img.setAlignment(QtCore.Qt.AlignCenter)
        self.lb_output_img.setObjectName("lb_output_img")
        self.horizontalLayout_2.addWidget(self.lb_output_img)
        self.verticalLayout.addLayout(self.horizontalLayout_2)
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout.addWidget(self.pushButton)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtWidgets.QApplication.translate("MainWindow", "滤镜处理", None, -1))
        self.pbtn_file.setText(QtWidgets.QApplication.translate("MainWindow", "选择图片文件", None, -1))
        self.cb_filter_list.setItemText(0, QtWidgets.QApplication.translate("MainWindow", "模糊滤镜", None, -1))
        self.cb_filter_list.setItemText(1, QtWidgets.QApplication.translate("MainWindow", "轮廓滤镜", None, -1))
        self.cb_filter_list.setItemText(2, QtWidgets.QApplication.translate("MainWindow", "边缘增强滤镜", None, -1))
        self.cb_filter_list.setItemText(3, QtWidgets.QApplication.translate("MainWindow", "浮雕滤镜", None, -1))
        self.cb_filter_list.setItemText(4, QtWidgets.QApplication.translate("MainWindow", "锐化滤镜", None, -1))
        self.cb_filter_list.setItemText(5, QtWidgets.QApplication.translate("MainWindow", "平滑滤镜", None, -1))
        self.pbtn_process.setText(QtWidgets.QApplication.translate("MainWindow", "开始处理", None, -1))
        self.lb_input_img.setText(QtWidgets.QApplication.translate("MainWindow", "处理前", None, -1))
        self.lb_output_img.setText(QtWidgets.QApplication.translate("MainWindow", "处理后", None, -1))
        self.pushButton.setText(QtWidgets.QApplication.translate("MainWindow", "保存处理结果", None, -1))

点赞1


评论


cool-creepercool-creeper

import tkinter as tk  
import tkinter.messagebox
import pickle

window = tk.Tk()

window.title('欢迎!')

window.geometry('400x300')

canvas = tk.Canvas(window, width=400, height=300, bg='blue')
image_file = tk.PhotoImage(file='这里填写你想要的图片的路径啦!')
image = canvas.create_image(200, 0, anchor='n', image=image_file)
canvas.pack(side='top')

tk.Label(window, text='用户名:', font=('黑体', 14)).place(x=10, y=175)
tk.Label(window, text='密码:', font=('黑体', 14)).place(x=10, y=218)


var_usr_name = tk.StringVar()
var_usr_name.set('')
entry_usr_name = tk.Entry(
    window, textvariable=var_usr_name, font=('Arial', 14))
entry_usr_name.place(x=120, y=175)

var_usr_pwd = tk.StringVar()
entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd,
                         font=('Arial', 14), show='*')
entry_usr_pwd.place(x=120, y=215)



def usr_login():
    usr_name = var_usr_name.get()
    usr_pwd = var_usr_pwd.get()
    try:
        with open('usrs_info.pickle', 'rb') as usr_file:
            usrs_info = pickle.load(usr_file)
    except FileNotFoundError:
        with open('usrs_info.pickle', 'wb') as usr_file:
            usrs_info = {'admin': 'admin'}
            pickle.dump(usrs_info, usr_file)
            usr_file.close()    
    if usr_name in usrs_info:
        if usr_pwd == usrs_info[usr_name]:
            tkinter.messagebox.showinfo(
                title='欢迎使用!', message='欢迎使用! ' + usr_name)
        else:
            tkinter.messagebox.showerror(
                title='密码错误!',message='密码错误,请重新输入')
    else:  
        is_sign_up=tkinter.messagebox.showerror(
            title='未找到此用户名。',message='未找到此用户名。')
        if is_sign_up:
            usr_sign_up()



def usr_sign_up():
    def sign_to_Hongwei_Website():
        np = new_pwd.get()
        npf = new_pwd_confirm.get()
        nn = new_name.get()

        with open('usrs_info.pickle', 'rb') as usr_file:
            exist_usr_info = pickle.load(usr_file)
        if np != npf:
            tkinter.messagebox.showerror(
                'Error', '密码不一致!')

        elif nn in exist_usr_info:
            tkinter.messagebox.showerror(
                'Error', '此用户已经注册了!')

        else:
            exist_usr_info[nn] = np
            with open('usrs_info.pickle', 'wb') as usr_file:
                pickle.dump(exist_usr_info, usr_file)
            tkinter.messagebox.showinfo(
                '欢迎使用!', '你可以登入、创造了!')
            window_sign_up.destroy()
    window_sign_up = tk.Toplevel(window)
    window_sign_up.geometry('300x200')
    window_sign_up.title('注册一个账户')

    new_name = tk.StringVar()  
    new_name.set('') 
    tk.Label(window_sign_up, text='用户名:').place(
        x=10, y=10)
    entry_new_name = tk.Entry(window_sign_up, textvariable=new_name)
    entry_new_name.place(x=130, y=10)
    new_pwd = tk.StringVar()
    tk.Label(window_sign_up, text='密码:').place(x=10, y=50)
    entry_usr_pwd = tk.Entry(window_sign_up, textvariable=new_pwd, show='*')
    entry_usr_pwd.place(x=130, y=50)

    new_pwd_confirm = tk.StringVar()
    tk.Label(window_sign_up, text='再次确认密码: ').place(x=10, y=90)
    entry_usr_pwd_confirm = tk.Entry(
        window_sign_up, textvariable=new_pwd_confirm, show='*')
    entry_usr_pwd_confirm.place(x=130, y=90)

    btn_comfirm_sign_up = tk.Button(
        window_sign_up, text='注册', command=sign_to_Hongwei_Website)
    btn_comfirm_sign_up.place(x=180, y=120)


btn_login = tk.Button(window, text='登录', command=usr_login)
btn_login.place(x=120, y=240)
btn_sign_up = tk.Button(window, text='注册', command=usr_sign_up)
btn_sign_up.place(x=200, y=240)

window.mainloop()

点赞0


评论


ZCH_ProZCH_Pro

center_image

emmmmmmmmmm

点赞0


评论


测试喵测试喵

import pygame as pg
import turtle as t
import sys
import random
import time
from pygame.locals import *
pg.init()
pg.mixer.init()

# 按W跳跃,鼠标点击切换模式,跑酷躲避障碍物

game_window = pg.display.set_mode((600, 500))
pg.display.set_caption('跑酷')
window_color = (255, 255, 255)
square_color = (255, 255, 255)
ground_color = (0, 0, 0)
z_color = (0, 0, 0)
score = 0
font = pg.font.Font(None, 70)
s = 400
gz = 620
gz1 = 900
gz3 = 900
gz4 = 620
m = 2
sp = 0
p = 1
c = [31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
     41, 42, 43, 44, 45, 46, 47, 48, 49, 50]
cs = 0
cy = 0.2
cm = 45
co = 0
while True:
    game_window.fill(window_color)
    for event in pg.event.get():
        if event.type == pg.QUIT:
            sys.exit()

    if cm > 10:
        cm -= cy
    else:
        cm = 45
    if event.type == MOUSEBUTTONDOWN and p == 1:
        p = 0
        sp += 1
        score += 2

    if event.type == MOUSEBUTTONUP:
        p = 1

    if sp % 2 == 1:
        if event.type == KEYDOWN:
            if event.key == K_w:
                pg.draw.rect(game_window, z_color, (0, 0, 600, 250))
                if (gz3 - gz4 < 100 and gz3 > gz4) or (gz4 - gz3 < 100 and gz4 > gz3):
                    gz3 += 200
                    pg.draw.rect(game_window, (100, 30, 255), (50, s, 30, 30))
                    pg.draw.rect(game_window, z_color, (gz, 250, 30, 30))
                    pg.draw.rect(game_window, z_color, (gz1, 300, 30, 30))
                    pg.draw.rect(game_window, square_color, (gz4, 220, 30, 30))
                    pg.draw.rect(game_window, square_color, (gz3, 155, 30, 30))
                else:
                    s = 155
                    pg.draw.rect(game_window, (100, 30, 255), (50, s, 30, 30))
                    pg.draw.rect(game_window, z_color, (gz, 250, 30, 30))
                    pg.draw.rect(game_window, z_color, (gz1, 300, 30, 30))
                    pg.draw.rect(game_window, square_color, (gz4, 220, 30, 30))
                    pg.draw.rect(game_window, square_color, (gz3, 155, 30, 30))
            else:
                s = 220
                pg.draw.rect(game_window, z_color, (0, 0, 600, 250))
                pg.draw.rect(game_window, (100, 30, 255), (50, s, 30, 30))
                pg.draw.rect(game_window, z_color, (gz, 250, 30, 30))
                pg.draw.rect(game_window, z_color, (gz1, 300, 30, 30))
                pg.draw.rect(game_window, square_color, (gz4, 220, 30, 30))
                pg.draw.rect(game_window, square_color, (gz3, 155, 30, 30))
        else:
            s = 220
            pg.draw.rect(game_window, z_color, (0, 0, 600, 250))
            pg.draw.rect(game_window, (100, 30, 255), (50, s, 30, 30))
            pg.draw.rect(game_window, z_color, (gz, 250, 30, 30))
            pg.draw.rect(game_window, z_color, (gz1, 300, 30, 30))
            pg.draw.rect(game_window, square_color, (gz4, 220, 30, 30))
            pg.draw.rect(game_window, square_color, (gz3, 155, 30, 30))
    elif sp % 2 == 0:
        if event.type == KEYDOWN:
            if event.key == K_w:
                pg.draw.rect(game_window, z_color, (0, 0, 600, 250))
                if (gz1 - gz < 100 and gz1 > gz) or (gz - gz1 < 100 and gz > gz1):
                    gz += 200
                    pg.draw.rect(game_window, (100, 30, 255), (50, s, 30, 30))
                    pg.draw.rect(game_window, z_color, (gz, 250, 30, 30))
                    pg.draw.rect(game_window, z_color, (gz1, 300, 30, 30))
                    pg.draw.rect(game_window, square_color, (gz4, 220, 30, 30))
                    pg.draw.rect(game_window, square_color, (gz3, 155, 30, 30))
                else:
                    s = 300
                    pg.draw.rect(game_window, (100, 30, 255), (50, s, 30, 30))
                    pg.draw.rect(game_window, z_color, (gz, 250, 30, 30))
                    pg.draw.rect(game_window, z_color, (gz1, 300, 30, 30))
                    pg.draw.rect(game_window, square_color, (gz4, 220, 30, 30))
                    pg.draw.rect(game_window, square_color, (gz3, 155, 30, 30))
            else:
                s = 250
                pg.draw.rect(game_window, (100, 30, 255), (50, s, 30, 30))
                pg.draw.rect(game_window, z_color, (0, 0, 600, 250))
                pg.draw.rect(game_window, z_color, (gz, 250, 30, 30))
                pg.draw.rect(game_window, z_color, (gz1, 300, 30, 30))
                pg.draw.rect(game_window, square_color, (gz4, 220, 30, 30))
                pg.draw.rect(game_window, square_color, (gz3, 155, 30, 30))
        else:
            s = 250
            pg.draw.rect(game_window, (100, 30, 255), (50, s, 30, 30))
            pg.draw.rect(game_window, z_color, (0, 0, 600, 250))
            pg.draw.rect(game_window, z_color, (gz, 250, 30, 30))
            pg.draw.rect(game_window, z_color, (gz1, 300, 30, 30))
            pg.draw.rect(game_window, square_color, (gz4, 220, 30, 30))
            pg.draw.rect(game_window, square_color, (gz3, 155, 30, 30))

    my_text = font.render(str(score), False, (255, 255, 255))
    game_window.blit(my_text, (500, 30))

    gz -= m
    gz1 -= m
    gz3 -= m
    gz4 -= m
    if 4 > score:
        m = 2
        cy = 0.4
    elif 10 > score:
        m = 2.5
        cy = 0.6
    elif 20 > score:
        m = 3
        cy = 0.8
    elif 30 > score:
        m = 3.5
        cy = 1
    elif 40 > score:
        m = 4
        cy = 1.2

    if gz <= 0:
        if sp % 2 == 0:
            score += 1

        gz = random.randint(620, 1800)
    if gz1 <= 0:
        if sp % 2 == 0:
            score += 1

        gz1 = random.randint(620, 1300)
    if gz3 <= 0:
        if sp % 2 == 1:
            score += 1

        gz3 = random.randint(620, 2300)
    if gz4 <= 0:
        if sp % 2 == 1:
            score += 1

        gz4 = random.randint(620, 700)
    pg.draw.rect(game_window, (100, 30, 255),
                 (cm + random.randint(3, 27), s + random.randint(3, 27), 10, 1))
    pg.draw.rect(game_window, (100, 30, 255),
                 (cm+random.randint(3, 27), s + random.randint(3, 27), 10, 1))
    pg.draw.rect(game_window, (100, 30, 255),
                 (cm+random.randint(3, 27), s + random.randint(3, 27), 10, 1))
    if event.type == MOUSEBUTTONDOWN:
        if cs < 3:
            pg.draw.rect(game_window, (random.randint(1, 255), random.randint(
                1, 255), random.randint(1, 255)), (0, 0, 1000, 1000))
            cs += 1
        else:
            cs = 0

    if (gz in c and s == 250) or (gz1 in c and s == 300):
        time.sleep(1)
        break
    if(gz4 in c and s == 220) or (gz3 in c and s == 115):
        time.sleep(1)
        break

    pg.display.update()

    time.sleep(0.005)

点赞0


评论


RmolusRmolus

你……是自学的吗……

点赞0


评论