Use Python to perform mathematical arithmetic operations for xiaobao _ arithmetic algorithm exercise program (add, subtract, multiply, divide)

Source: Internet
Author: User

Use Python to perform mathematical arithmetic operations for xiaobao _ arithmetic algorithm exercise program (add, subtract, multiply, divide)

 

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 )!

# Gaming for xiaobao:


Import string
Import random
Input = 11
Nums = 10
Num = 0
Righ1t = 0 # score #
Flagwrong = 0 # Yes
Print e [1; 34 mThis text is bold blue. e [0 m
Print has 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) % 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 is coming soon!
Break;
Elif num Num = num + 1

X = random. randint (1,100) # numbers less than 100
Y = random. randint (1, 10)
Print


Symbol = random. randint (0, 3)
# Symbol = 3 # test division #
If 0 = symbol: # Addition
# Inner Loop-question preparation
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, you cannot increase your score (score ).
Print 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 preparation
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, you cannot increase your score (score ).
Print 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 preparation
# 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, you cannot increase your score (score ).
Print 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 preparation
If x Print question % d: % d/% d = % (num, x, y ),
Print vendor? :,

Input = raw_input ()
Intp = string. atoi (input)
What is the print remainder? :,
Input2yushu = raw_input ()
Intp2yushu = string. atoi (input2yushu)


Print vendor :,
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, you cannot increase your score (score ).
Print again, question % d: % d/% d operator =? % (Num, x, y ),
Input = raw_input ()
Intp = string. atoi (input)
Print surplus? =,
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 within 100

Num = 0

 

 


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.