Simple printing with Python
print(3+2)
print(1-2)
print(3*4)
print(2/6)
print(2*3+5-2)
print(4/2+5)
Simple if structure in Python
q=int(input("Key in a number: "))
if q<0:
print(q," < 0")
elif q>0:
print(q," > 0")
else:
56
print(q," = 0")
for i in range(1,10,1):
print(i)
For with string
#print with enter
for x in 'hello':
print(x)
#print without enter
for x in 'hello':
print(x,end="")
Nested For Loop in Python
for i in range(5):
for j in range(4):
print("i =",i," j = ",j)
Nested for with if structure
import sys
for i in range(8):
for j in range(i):
if j==i-1:
print("")
else:
sys.stdout.write('*')
For loop and break
myGirlfriends=['Kate','Mary','Jane','Frida']
x=input("Key in a name, please: ")
for i in range(len(myGirlfriends)):
if x == myGirlfriends[i]:
print("Mrs ",x," is my girlfriend.")
break
else:
print("Mrs ",x," is not my girlfriend.")
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου