[python second day study notes]

Design your first game in python

1. Shortcut to run idle: F5

Second, first design a small game:

print('-------Start python learning journey-------')
temp = input("Let's guess which number the turtle is thinking about now:")
guess = int( temp)
if guess ==8:
    print("Fuck, are you a roundworm in the belly of the small turtle?")
    print("There is no reward for the right guess")
else:
    print("The guess is wrong, the small turtle is now in the heart What I'm thinking about is 8!")
print("The game is over, stop playing!")
----python especially emphasizes indentation, different indentation will print different results

The meaning of the upper-end program:

temp = input("Let's guess which number the turtle is thinking about now:") input is a built-in function of python, which is assigned to the temp variable through input

guess = int(temp) int(temp): Cast the character type of temp to an integer; then assign it to the guess variable so that the following numbers can be input

if guess ==8:
    print("Fuck, are you a roundworm in the belly of the little turtle?")
    print("There is no reward if you guess correctly")
else:
    print("The guess is wrong, the turtle is thinking now is 8!") if statement

print("The game is over, stop playing!") The game outputs the printed content as a whole, not in the if statement

3. Grammar:

Assignment: The value on the right is assigned to the variable on the left through =, and the one on the left is used to accept (temp = input("")

Abbreviation for built-in functions: BIF = Built-in functions

Check how many bifs there are: enter in idle: dir(__bulitins__) to see the list of bifs, a total of 68

Check the meaning of a specific bif: such as: input() help(input)

4. Exercise after class:

1. Write a program: hello.py, go to the user to enter the name and print "Hello, name!"

name= input('Please enter your name:')
print('Hello, '+name+'!')

2. Write a program: calc.py, ask the user to input a number between 1 and 100 and judge, enter a number that meets the requirements to print "Hello!", and print "You are too stupid!" if it does not meet the requirements

temp = input('Please enter a number between 1 and 100:')
num=int(temp)
if 0<=num<=100:
    print("You are awesome")
else:
    print("You are stupid !")
print("Game over!")

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324643591&siteId=291194637
Recommended