python actual combat 90 lines of code to write a guess number game
- 2021-11-01 03:57:08
- OfStack
1. Import the library
import random
import time
2. Register users
We use variables and input to implement
name = str(input(' Please enter a user name :'))
print(' Welcome, '+name)
3. Age of registration
Here we have to use except to make random text on the end of the game program
Indiscriminate typing of text is over
try:
age = int(input(' Please enter an age :'))
except ValueError:
print(' Illegal importation ')
age = 30000
By the way, set the age to 30,000 [funny]
Then distribute gold coins according to age
STEP 4 Allocate Gold Coins
if age <10:
gold = 500
print(' Your initial gold coin is 500')
if age <20 and age >10:
gold = 1000
print(' Your initial gold coin is 1000')
if age >20 and age <30:
gold = 1500
print(' Your initial gold coin is 1500')
if age >30 and age <1000:
gold = 200
print(' If you are too old, your initial gold coin is 200')
Use if statement to ensure that the gold coin is less than 10000. If it is equal to 10000, the game is over
5. if Judgement 1
if gold !=10000:
Game_start = str(input(' Do you want to start the game? (True Or False)'))
while gold !=10000:
Next is the most important part of the game, seriously!
We also have to use the if statement to determine that the Game_start variable is True and create a list of random numbers
6. if and Random Numbers
if Game_start =='True':
list_123 = [random.randint(1,6),random.randint(1,6),random.randint(1,6),]
while list_123 ==10:
list_123 = [random.randint(1,6),random.randint(1,6),random.randint(1,6),]
Then set the answer variables and the correct answer and the wrong answer
7. Answer, right and wrong
answer = str(input(' Guess, please (big Or small):'))
if list_123[0] + list_123[1] + list_123[2] >10:
result = 'big'
error_result = 'small'
if list_123[0] + list_123[1] + list_123[2] <10:
result = 'small'
error_result = 'big'
You have to use the if statement to judge the correct, wrong and illegally entered answers
8. if Judgement 2
if answer ==result:
print(' You won! ')
gold = gold + 100
print(' Random number is '+str(list_123))
print(' You now have '+str(gold)+' Gold coin ')
elif answer ==error_result:
print(' You lost ...')
print(' Random number is '+str(list_123))
gold = gold - 100
print(' You now have '+str(gold)+' Gold coin ')
else:
print(' Illegal importation ')
gold = 10000
Then make a module for purchasing props
It's too long. I'm too lazy to write sentence by sentence
9. Buy props
if gold ==2000 or gold ==3000 or gold ==4000 or gold ==5000 or gold ==6000 or gold ==7000 or gold ==8000 or gold ==9000:
answer = str(input(' You can buy props now, do you want to buy them ?(True Or False):'))
if answer =='True':
print(' Please state what you want to buy der Props ')
print('*'*41)
print('* Gold coin doubler [ Existing ] Gold coin doubler [ Get ]*')
print('* 2000G 1500G *')
print('*'*41)
answer = str(input(' Please state what you want to buy der Props ( Gold coin doubler [ Existing ] Say 1 Gold coin doubler [ Get ] Say 2):'))
if gold >2000 and answer =='1':
gold = gold - 2000
answer = int(input(' Please say what you want to turn over der Multiple :'))
gold = str(gold * answer)
print(' You now have '+gold+' Gold coin ')
gold = int(gold)
elif gold >1500 and answer =='2':
gold = gold - 1500
answer = int(input(' Please say what you want to turn over der Multiple :'))
gold_mang = 100 * answer
gold = gold + gold_mang
print(' You now have '+str(gold)+' Gold coin ')
gold = int(gold)
else:
print(' Without this prop, the game is over ')
gold = 10000
elif answer =='False':
print(' Continue the game ')
else:
print(' Illegal importation ')
gold = 10000
I wrote 1 and a half and found that I didn't bridge the above, so let's bridge it now
10. Bridging
import random
import time
name = str(input(' Please enter a user name :'))
print(' Welcome, '+name)
try:
age = int(input(' Please enter an age :'))
except ValueError:
print(' Illegal importation ')
age = 30000
gold = 10000
if age <10:
gold = 500
print(' Your initial gold coin is 500')
if age <20 and age >10:
gold = 1000
print(' Your initial gold coin is 1000')
if age >20 and age <30:
gold = 1500
print(' Your initial gold coin is 1500')
if age >30 and age <1000:
gold = 200
print(' If you are too old, your initial gold coin is 200')
if gold !=10000:
Game_start = str(input(' Do you want to start the game? (True Or False)'))
while gold !=10000:
if Game_start =='True':
list_123 = [random.randint(1,6),random.randint(1,6),random.randint(1,6),]
while list_123 ==10:
list_123 = [random.randint(1,6),random.randint(1,6),random.randint(1,6),]
answer = str(input(' Guess, please (big Or small):'))
if list_123[0] + list_123[1] + list_123[2] >10:
result = 'big'
error_result = 'small'
if list_123[0] + list_123[1] + list_123[2] <10:
result = 'small'
error_result = 'big'
if answer ==result:
print(' You won! ')
gold = gold + 100
print(' Random number is '+str(list_123))
print(' You now have '+str(gold)+' Gold coin ')
elif answer ==error_result:
print(' You lost ...')
print(' Random number is '+str(list_123))
gold = gold - 100
print(' You now have '+str(gold)+' Gold coin ')
else:
print(' Illegal importation ')
gold = 10000
if gold ==2000 or gold ==3000 or gold ==4000 or gold ==5000 or gold ==6000 or gold ==7000 or gold ==8000 or gold ==9000:
answer = str(input(' You can buy props now, do you want to buy them ?(True Or False):'))
if answer =='True':
print(' Please state what you want to buy der Props ')
print('*'*41)
print('* Gold coin doubler [ Existing ] Gold coin doubler [ Get ]*')
print('* 2000G 1500G *')
print('*'*41)
answer = str(input(' Please state what you want to buy der Props ( Gold coin doubler [ Existing ] Say 1 Gold coin doubler [ Get ] Say 2):'))
if gold >2000 and answer =='1':
gold = gold - 2000
answer = int(input(' Please say what you want to turn over der Multiple :'))
gold = str(gold * answer)
print(' You now have '+gold+' Gold coin ')
gold = int(gold)
elif gold >1500 and answer =='2':
gold = gold - 1500
answer = int(input(' Please say what you want to turn over der Multiple :'))
gold_mang = 100 * answer
gold = gold + gold_mang
print(' You now have '+str(gold)+' Gold coin ')
gold = int(gold)
else:
print(' Without this prop, the game is over ')
gold = 10000
elif answer =='False':
print(' Continue the game ')
else:
print(' Illegal importation ')
gold = 10000
In fact, we have basically finished here, but if we only write here, there will be a lot of bug, and we can play this version if we don't want to see it.
There are still 1 code left, and I am too lazy to write it. I will directly complete the code
101. Complete code
name = str(input(' Please enter a user name :'))
print(' Welcome, '+name)
0