Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Arithmetic-Integer/Python/arithmetic-integer-1.py
Normal file
14
Task/Arithmetic-Integer/Python/arithmetic-integer-1.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
x = int(raw_input("Number 1: "))
|
||||
y = int(raw_input("Number 2: "))
|
||||
|
||||
print "Sum: %d" % (x + y)
|
||||
print "Difference: %d" % (x - y)
|
||||
print "Product: %d" % (x * y)
|
||||
print "Quotient: %d" % (x / y) # or x // y for newer python versions.
|
||||
# truncates towards negative infinity
|
||||
print "Remainder: %d" % (x % y) # same sign as second operand
|
||||
print "Quotient: %d with Remainder: %d" % divmod(x, y)
|
||||
print "Power: %d" % x**y
|
||||
|
||||
## Only used to keep the display up when the program ends
|
||||
raw_input( )
|
||||
13
Task/Arithmetic-Integer/Python/arithmetic-integer-2.py
Normal file
13
Task/Arithmetic-Integer/Python/arithmetic-integer-2.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
def getnum(prompt):
|
||||
while True: # retrying ...
|
||||
try:
|
||||
n = int(raw_input(prompt))
|
||||
except ValueError:
|
||||
print "Input could not be parsed as an integer. Please try again."\
|
||||
continue
|
||||
break
|
||||
return n
|
||||
|
||||
x = getnum("Number1: ")
|
||||
y = getnum("Number2: ")
|
||||
...
|
||||
8
Task/Arithmetic-Integer/Python/arithmetic-integer-3.py
Normal file
8
Task/Arithmetic-Integer/Python/arithmetic-integer-3.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
def arithmetic(x, y):
|
||||
for op in "+ - * // % **".split():
|
||||
expr = "%(x)s %(op)s %(y)s" % vars()
|
||||
print("%s\t=> %s" % (expr, eval(expr)))
|
||||
|
||||
|
||||
arithmetic(12, 8)
|
||||
arithmetic(input("Number 1: "), input("Number 2: "))
|
||||
21
Task/Arithmetic-Integer/Python/arithmetic-integer-4.py
Normal file
21
Task/Arithmetic-Integer/Python/arithmetic-integer-4.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
input1 = 18
|
||||
# input1 = input()
|
||||
input2 = 7
|
||||
# input2 = input()
|
||||
|
||||
qq = input1 + input2
|
||||
print("Sum: " + str(qq))
|
||||
ww = input1 - input2
|
||||
print("Difference: " + str(ww))
|
||||
ee = input1 * input2
|
||||
print("Product: " + str(ee))
|
||||
rr = input1 / input2
|
||||
print("Integer quotient: " + str(int(rr)))
|
||||
print("Float quotient: " + str(float(rr)))
|
||||
tt = float(input1 / input2)
|
||||
uu = (int(tt) - float(tt))*-10
|
||||
#print(tt)
|
||||
print("Whole Remainder: " + str(int(uu)))
|
||||
print("Actual Remainder: " + str(uu))
|
||||
yy = input1 ** input2
|
||||
print("Exponentiation: " + str(yy))
|
||||
Loading…
Add table
Add a link
Reference in a new issue