Use Python to perform mathematical arithmetic operations for xiaobao-arithmetic algorithm exercise program (plus, subtraction, multiplication, division) and python arithmetic operations

Source: Internet
Author: User

Use Python to perform mathematical arithmetic operations for xiaobao-arithmetic algorithm exercise program (plus, subtraction, multiplication, division) and python arithmetic operations

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 [0m \ n"
Print "A total of % d questions:" % (nums)
Print "\ e [33; 45; 1 mBold yellow on magenta. \ e [0 m \ n ";
While True:
Flagwrong = 0
If num> = nums:
Print "% d path/% d path question (once)" % (righ1t, nums ),
If righ1t> = 10:
Print "You are awesome! 100 points !!! "
Elif righ1t> = 8:
Print "you are good, 80 points or more !!! "
Else:
Print "you have to cheer up! "
Break;
Elif num <nums:
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 "No! % 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 "Yes! % 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 <y: x01temp = x; x = y; y = x01temp;
Print "question % d: % d-% d =" % (num, x, y ),
Input = raw_input ()
Intp = string. atoi (input)
Print intp
While intp! = (X-y ):
Print "No! % 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 "Yes! % 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 <y: x01temp = x; x = y; y = x01temp;
Print "question % d: % d * % d =" % (num, x, y ),
Input = raw_input ()
Intp = string. atoi (input)
Print intp
While intp! = (X * y ):
Print "No! % D * % d is not equal to % d "% (x, y, intp)
Flagwrong = 1; # If you miss one, you cannot increase your score (score ).
Print "Calculate 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 "Yes! % 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 <y: x01temp = x; x = y; y = x01temp;
Print "question % d: % d/% d =" % (num, x, y ),
Print "vendor? :",

Input = raw_input ()
Intp = string. atoi (input)
Print "what is the remainder? :",
Input2yushu = raw_input ()
Intp2yushu = string. atoi (input2yushu)


Print "vendor :",
Print intp,
Print "the remainder is :",
Print intp2yushu

While x! = (Intp * y) + intp2yushu ):
Print "No! % 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 "Yu? = ",
Input2yushu = raw_input ()
Intp2yushu = string. atoi (input2yushu)

If x = (intp * y + intp2yushu ):
Break;
Continue;
If x = (intp * y) + intp2yushu ):
Print "Yes! % 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

------------------------------------------------------------------------


"Indentation problem" is temporarily selected (Gray) and then indented with the <Tab> key ......

Indentation is still a problem!

In the future, I hope Python can add {} (code block, or: Use "end" to end the code block ...... Rather than force indent!


========================================================== ==================================


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.