Four arithmetic operations done with Python: arithmetic operation exercise program (plus, subtraction, multiplication, division) and python operation

Source: Internet
Author: User

Four arithmetic operations done with Python: arithmetic operation exercise program (plus, subtraction, multiplication, division) and python operation

Recently fascinated by Python

The math calculation exercise program for xiaobao using Python (four arithmetic operations added in January 2015 )!

The oral computing game for xiaobao:

# The math arithmetic exercise program that I used for Xiao Bao using Python (four arithmetic operations added in January 2015 )! # The Script game for xiaobao: import string import random input = 11 nums = 10 num = 0 righ1t = 0 # score # flagwrong = 0 # print e [1; 34 mThis text is bold blue. e [0 m print a total of % d questions: % (nums) print e [33; 45; 1 mBold yellow on magenta. e [0 m; while True: flagwrong = 0 if num> = nums: print (once in total) Correct % d path/% d path question % (righ1t, nums), if righ1t> = 10: print! 100 points !!! Elif righ1t> = 8: print you are good, 80 points or more !!! Else: print. Come on! Break; elif num = num + 1 x = random. randint (1,100) # number less than 100 y = random. randint (1, 10) print symbol = random. randint () # symbol = 3 # test division # if 0 = symbol: # Addition # Inner Loop-print question % d: % d + % d = % (num, x, y), input = raw_input () intp = string. atoi (input) print intp while intp! = (X + y): print is incorrect! % D + % d is not equal to % d % (x, y, intp) flagwrong = 1; # If you miss one time, you cannot increase the score (score). print and calculate it again, question % d: % d + % d = % (num, x, y), input = raw_input () intp = string. atoi (input) if intp = x + y: break; continue; if intp = (x + y): print is correct! % D + % d is equal to % d % (x, y, intp) if flagwrong = 0: righ1t = righ1t + 1 continue; break; elif 1 = symbol: # subtraction # Inner Loop-question if x print question % d: % d-% d = % (num, x, y), input = raw_input () intp = string. atoi (input) print intp while intp! = (X-y): print is incorrect! % D-% d is not equal to % d % (x, y, intp) flagwrong = 1; # If you miss one time, you cannot increase the score (score). print and calculate it again, question % d: % d-% d = % (num, x, y), input = raw_input () intp = string. atoi (input) if intp = x-y: break; continue; if intp = (x-y): print is correct! % D-% d is equal to % d % (x, y, intp) if flagwrong = 0: righ1t = righ1t + 1 continue; break; elif 2 = symbol: # multiplication # Inner Loop-Question # if x print question % d: % d * % d = % (num, x, y), input = raw_input () intp = string. atoi (input) print intp while intp! = (X * y): print is incorrect! % D * % d is not equal to % d % (x, y, intp) flagwrong = 1; # If you miss one time, you cannot increase the score (score). print and calculate it again, question % d: % d * % d = % (num, x, y), input = raw_input () intp = string. atoi (input) if intp = x * y: break; continue; if intp = (x * y): print is correct! % D * % d is equal to % d % (x, y, intp) if flagwrong = 0: righ1t = righ1t + 1 continue; break; elif 3 = symbol: # Division # Inner Loop-question if x print question % d: % d/% d = % (num, x, y), print operator? :, Input = raw_input () intp = string. atoi (input) print remainder? :, Input2yushu = raw_input () intp2yushu = string. atoi (input2yushu) print OPERATOR:, print intp, print remainder:, print intp2yushu while x! = (Intp * y) + intp2yushu): print is incorrect! % D/% d is not equal to quotient % d, remainder % d! % (X, y, intp, intp2yushu) flagwrong = 1; # If you miss one time, you cannot increase the score (score) by calculating print again. Question % d: % d/% d operator =? % (Num, x, y), input = raw_input () intp = string. atoi (input) print remainder? =, Input2yushu = raw_input () intp2yushu = string. atoi (input2yushu) if x = (intp * y + intp2yushu): break; continue; if x = (intp * y) + intp2yushu): print is correct! % D/% d is equal to quotient % d, remainder % d! % (X, y, intp, intp2yushu) if flagwrong = 0: righ1t = righ1t + 1 continue; break; # Addition/subtraction/multiplication/division num = 0 within 100

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.