Home > other >  Python programming code (o)
Python programming code (o)

Time:12-02

Develop a cycle calculation of the five small game, every time randomly generated two 1 ~ 10 Numbers and random selection operator "+, -, *", constitute an expression, allow the user to calculate formula results and enter the result, if the calculation result is correct, if you don't bonus calculation error, accuracy is greater than or equal to 80%, if we print "recruit success", otherwise print "recruit is not successful,"

CodePudding user response:

 import random 

Score=0
For I in range (5) :
Num1=random. Randint (1, 9)
Num2=random. Randint (1, 9)
Symbol_list={1: '+', 2: '-', 3: '*'}
Symbol=the random choice ([1, 2, 3])
Print (' {} {} {}=? 'the format (num1, symbol_list (symbol), num2))
If the symbol==1:
Result=num1 + num2
Elif symbol==2:
Result=num1 - num2
The else:
Result=num1 * num2
Answer=int (input (' please enter the correct answer: '))
If the result==answer:
Score +=1

Print (' accuracy: {} % '. The format (100) score/5 *)
If score & lt; 4:
Print (' recruit failure)
The else:
Print (' recruit successful ')

CodePudding user response:

reference 1st floor zzzzzyyy12 response:
 import random 

Score=0
For I in range (5) :
Num1=random. Randint (1, 9)
Num2=random. Randint (1, 9)
Symbol_list={1: '+', 2: '-', 3: '*'}
Symbol=the random choice ([1, 2, 3])
Print (' {} {} {}=? 'the format (num1, symbol_list (symbol), num2))
If the symbol==1:
Result=num1 + num2
Elif symbol==2:
Result=num1 - num2
The else:
Result=num1 * num2
Answer=int (input (' please enter the correct answer: '))
If the result==answer:
Score +=1

Print (' accuracy: {} % '. The format (100) score/5 *)
If score & lt; 4:
Print (' recruit failure)
The else:
Print (' recruit successful ')

Thank you very much for your help
  • Related