python workshop ans
unknown
python
2 years ago
2.3 kB
16
Indexable
#1
a = 100
b = 30
print(a, " + ", b, " = ", a+b)
print(a, " - ", b, " = ", a-b)
print(a, " * ", b, " = ", a*b)
print(a, " / ", b, " = ", a/b)
print(a, " % ", b, " = ", a%b)
#2
a = eval(input("First Number: "))
b = eval(input("Second Number: "))
op = input("Operator: ")
if op == '+':
print(a+b)
elif op == '-':
print(a-b)
elif op == '*':
print(a*b)
elif op == '/':
print(a/b)
else:
print("Invalid Operator")
# 3
import turtle as t
n = int(input("number of sides: "))
for _ in range(n):
t.fd(100)
t.lt(360/n)
t.done()
#4
import turtle as t
n = eval(input("input n: "))
for j in range(n):
for i in range(n):
if j % 2 == 0 and i % 2 == 0:
t.begin_fill()
for _ in range(4):
t.fd(100/n)
t.rt(90)
t.end_fill()
elif j % 2 != 0 and i % 2 != 0:
t.begin_fill()
for _ in range(4):
t.fd(100/n)
t.rt(90)
t.end_fill()
else:
for _ in range(4):
t.fd(100/n)
t.rt(90)
t.begin_fill()
t.fd(100/n)
t.rt(90)
t.fd(100/n)
t.rt(90)
t.fd(100)
t.rt(180)
t.done()
#5
x = eval(input("Input your amount of money: "))
display = ""
if x / 1000 >= 1:
thouds = x // 1000
x -= thouds*1000
display += f"1000-Baht notes: {thouds}\n"
if x / 500 >= 1:
fhunds = x // 500
x -= fhunds*500
display += f"500-Baht notes: {fhunds}\n"
if x / 100 >= 1:
hunds = x // 100
x -= hunds*100
display += f"100-Baht notes: {hunds}\n"
if x / 50 >= 1:
ftys = x // 50
x -= ftys*50
display += f"50-Baht notes: {ftys}\n"
if x / 20 >= 1:
twtys = x // 20
x -= twtys*20
display += f"20-Baht notes: {twtys}\n"
if x / 10 >= 1:
tens = x // 10
x -= tens*10
display += f"10-Baht coins: {tens}\n"
if x / 5 >= 1:
fives = x // 5
x -= fives*5
display += f"5-Baht coins: {fives}\n"
if x / 2 >= 1:
twos = x // 2
x -= twos*2
display += f"2-Baht coins: {twos}\n"
if x / 1 > 0:
ones = x
display += f"1-Baht coins: {ones}\n"
print(display)Editor is loading...