Learning how to compile a simple multiplication algorithm in python and how to perform a multiplication in python
Implementation Code:
#! /Usr/bin/python // handler # filename jiafa. py // file name import sys import random running = True // define running while running: a = random. randint () // defines a random number ranging from 0 to 15. B = random. randint () // defines the random number print ,'*', B // output question he = a * B gauess = int (raw_input ('Please answer: ') // defines the user input value if gauess = he: // determine whether the user input is equal to the actual value print "right! Continue? Y/N "// if the values are equal, the output is correct and you are asked whether to continue fd = raw_input (" please Enter :") // obtain the keyboard input value str1 = 'y' zhi = cmp (fd, str1) if zhi = 0: // determine whether the keyboard input value is Y, if yes, execute and exit. If not, return to while again and output the new question print "this is over" sys. exit () elif gauess
If the test is performed, pay attention to the format