Home > other >  New inquire, not both
New inquire, not both

Time:09-27

1
Xiao Ming elementary school second grade this year, but the math exam will not pass, xiaoming mother request you to develop a small program can
Xiao Ming based computing power to exercise, every time this program should provide five random addition or multiplication subject to
Xiao Ming for problem solving, xiao Ming if right should be praised for his if wrong should comfort him, and told he is
Is the answer, through the menu can choose to practice or multiplication addition, unless xiaoming mother input instructions,
Program won't quit, each subject should be is two the number of addition and multiplication, the number 1-100,
The second number 1-10 of less than,
The output of the program shall be in conformity with the following example, the green font for the user's input:
a> Add test m> Multiplication test q> Out

Please enter a command (a/m/q) : a
9 + 2= 11
Correct answer! You are great!
74 + 6= 80
Correct answer! You are great!
37 + 6= 5
Also need to be more careful! The correct answer is 43
87 + 4= 5
Also need to be more careful! The correct answer is actually 91
11 + 9= 4
Also need to be more careful! The correct answer is 20

a> Add test m> Multiplication test q> Out
Please enter a command (a/m/q) : m
22 * 4= 88
Correct answer! You are great!
43 * 9= 5
Also need to be more careful! The correct answer is actually 387
27 * 5= 135
Correct answer! You are great!

a> Add test m> Multiplication test q> Out
Please enter a command (a/m/q) : q
Xiao Ming goodbye! You will come back


The second question
Classic, guess the Numbers, the program randomly generates a number between 0 and 100, allow users to guess each
User after speculation, update tip number range, and the program should limit the user to guess the number, by making
The user to select difficulty confirmation number limit, simple difficulty 10 times, normal difficulty eight times, difficult difficult 5 times,
Hell difficulty 3 times,
Procedures shall strictly comply with the following example, the green font for user input
* * * * * * * * guess Numbers game * * * * * * * *
You can within a limited opportunity to a 0-100 scale digital kitchen knife?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
(please select a difficulty (simple [S] [N]/[D]/[H]) hell difficulty: S
Simple is difficult, you have 10 times opportunity

The first guess: the number between 0-100: 50
Guess wrong! The number is less than 50

The second guess, the number between 0 and 49: and
Guess wrong! The number is less than 26

Guess for the third time, the number between 0 and 25: 13
Guess wrong! The number is less than 13

Fourth is forecasted, the number between 0-12: 13
Invalid input! Please enter a number between 0 and 12

Fourth is forecasted, the number between 0-12: 6
Guess wrong! The number is greater than 6

Fifth is forecasted, the number between 7-12: 5
Invalid input! Please enter a number between 7 to 12

Fifth is forecasted, the number between 7-12: 10
Guess wrong! The number is less than 10

Sixth is forecasted, the number between 7-9:
Guess wrong! The number is greater than 8

Guess, for the seventh time the number between 9-9: 9
Congratulations to you! After seven times try, finally guessed right!

* * * * * * * * guess Numbers game * * * * * * * *
You can within a limited opportunity to a 0-100 scale digital kitchen knife?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
(please select a difficulty (simple [S] [N]/[D]/[H]) hell difficulty: H
Hell difficulty, you have three chances to

Guess the first time, the number between 0-100: 80
Guess wrong! The number is less than 80

The second guess, the number between 0-79: 60
Guess wrong! The number is greater than 60

Guess for the third time, the number between 61-79: 66
Guess wrong! The number is larger than 66
Very sorry! Your chance to run out!

CodePudding user response:

Is pretty simple, can try to write about himself first,
Don't care if, how much to write and write first!

CodePudding user response:

Give you write the first!
The second hope you can one instance!
Are really just the use of random Numbers!
 
Import the random

Def add (times) :
While times> 0:
Add_param1=random. Randint (1100)
Add_param2=random. Randint (1, 10)
Correct_result=add_param1 + add_param2
Input_result=input (" {} + {}=". The format (add_param1 add_param2))
If the STR (correct_result)==input_result:
Print (" the correct answer! You are great!" )
The else:
Print (" needs to be more careful! The correct answer is "+ STR (correct_result))
Times -=1

Def the mul (times) :
While times> 0:
Mul_param1=random. Randint (1100)
Mul_param2=random. Randint (1, 10)
Correct_result=mul_param1 * mul_param2
Input_result=input (" {} {} *=". The format (mul_param1 mul_param2))
If the STR (correct_result)==input_result:
Print (" the correct answer! You are great!" )
The else:
Print (" needs to be more careful! The correct answer is "+ STR (correct_result))
Times -=1

Def the main () :
While True:
CMD=input (" please input command (a/m/q) : ")
If CMD=='q:
Print (" xiaoming goodbye! You'll be back ")
Break
Elif CMD=='a' :
Add (5)
Elif CMD=='m:
The mul (3)
The else:
Print (" order error, please input again!" )

If __name__=="__main__ ':
The main ()

CodePudding user response:

Really not difficult, it is suggested that more than look at the statement, the input and the while loop
  • Related