A complete collection of python game codes that can be copied, the simplest game code in python

Hello everyone, the editor will answer the question of programming the simplest game code in python. Many people still don’t know the introductory game code for python game programming, let’s take a look at it now!

0. Background:

As a python novice, I watched some python tutorials from the Rookie Tutorial today and saw some syntax of python. In comparison (with other language skills), I found it very interesting, so I added a little content and changed a small Routine, practice it in front of you, and it feels very efficient to get started with some small examples.

1. Code content:

Not much more to say, let’s go directly to the code:

import random
rang1 = int(input("请设置本局游戏的最小值:"))
rang2 = int(input("请设置本局游戏的最大值:"))
num = random.randint(rang1,rang2)
guess = "guess"
print("数字猜谜游戏!")
i = 0
while guess != num:
    i += 1
    guess = int(input("请输入你猜的数字:"))
 
    if guess == num:
        print("恭喜,你猜对了!")
    elif guess < num:
        print("你猜的数小了...")
    else:
        print("你猜的数大了...")
 
print("你总共猜了%d" %i + "次",end = '')
print(",快和你朋友较量一下...")

The content of the game is very simple. I believe anyone who wants to learn can understand it. I won’t explain it. After playing it myself, I found that the mini-game is quite magical. There are still many ways to improve the game. I hope this will increase your interest in programming. Lokomotiv Pseudo Original URL [php source code] .

About Python Technical Reserve

It is good to learn Python whether it is employment or sideline business to make money, but to learn Python, you still need a study plan. Finally, we share a complete set of Python learning materials to give some help to those who want to learn Python!

Click here to get it for free: CSDN gift package: "python learning route & full set of learning materials" free sharing

1. Learning routes in all directions of Python

The technical points in all directions of Python are organized to form a summary of knowledge points in various fields. Its usefulness is that you can find corresponding learning resources according to the above knowledge points to ensure that you learn more comprehensively.
Insert image description here

2. Essential development tools for Python

Insert image description here

3. Python video collection

Watch zero-based learning videos. Watching videos is the fastest and most effective way to learn. It is easy to get started by following the teacher's ideas in the video, from basic to in-depth.
Insert image description here

4. Practical cases

Optical theory is useless. You must learn to follow along and practice it in order to apply what you have learned to practice. At this time, you can learn from some practical cases.Insert image description here

5. Python exercises

Check the learning results.
Insert image description here

6. Interview information

We must learn Python to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and Alibaba bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.
Insert image description here
Insert image description here
This complete version of the complete set of Python learning materials has been uploaded to CSDN. If you need it, friends can scan the CSDN official certification QR code below on WeChat to get it for free [Guaranteed 100% free]

Guess you like

Origin blog.csdn.net/mynote/article/details/132797695