0% found this document useful (0 votes)
8 views3 pages

Python Loop Condition Examples

The document contains various examples of Python loops and conditional statements. It demonstrates the use of while loops, if-else conditions, and for loops with different data types and operations. The examples cover arithmetic operations, string manipulation, and control flow in Python programming.

Uploaded by

seungmiin1020
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Python Loop Condition Examples

The document contains various examples of Python loops and conditional statements. It demonstrates the use of while loops, if-else conditions, and for loops with different data types and operations. The examples cover arithmetic operations, string manipulation, and control flow in Python programming.

Uploaded by

seungmiin1020
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Loop and Condition Examples

num = 111
while num <= 2:
print(num)
num += 1

num = 111
num2 = num - (num - 1)
while num2 <= num:
print(num)
num2 += 1

num = 111

i = 1
while i <= num:
print('', num)
i += 1

num = 111

i = 1
while i <= num:
print('', i, '', i**2)
i += 1

num = 111

i = 1
while i <= 10:
print(i, round(num,4))
num *= 3/5
i += 1

count = 3
while count > 0:
print(count)
count -= 1

a = 1234 * 4
b = 13456 / 2

if a <= b:
print('b')
else:
print('a')

a = 48
b = 5
if a % b == 0:
print('0')
else:
print('not 0')

max = 10
while True:
num = 50
if num > max:
print('no')
break

num = 3
if num == 111:
print('1')
elif num == 2:
print('2')
else:
print('3')

num = 2026 - 111 + 1

if num <= 1924:


print('The Greatest Generation')
elif num >= 1925 and num <= 1945:
print('The Silent Generation')
elif num >= 1945 and num <= 1964:
print('baby boomer')
elif num >= 1965 and num <= 1980:
print('Generation X')
elif num <= 1996:
print('millennial')
else:
print('Generation Z')

num = 111
result = str(num)

if num >= 100000:


result = str(num//100000) + 'M'
elif num >= 0:
pass

print(result)

total = 0
num = 111

while num >= 0:


total += num
num = 111
if num < 0:
print(str(total))
break

sum = 0

while True:
num = 111
if num < 0:
break
else:
sum += num

print(sum)

year = None
Y = 111

if Y % 4 == 0:
if Y % 100 == 0:
if Y % 400 == 0:
year = True
else:
year = False
else:
year = True
else:
year = False

if year:
print('leap year')
else:
print('common year')

s = 'a b c d e f'
result = [Link](' ', 4)
print(result)

mp, bp = map(int, input().split())


tem = int(input())

while tem != -999:


if mp <= tem <= bp:
print('Nothing to report')
tem = int(input())
else:
print('Alert')
break

text = input()
lines = [Link]()

g = 1
h = 0

if g*h > 0 and g/h > 0:


print('yes')

list1 = ['a', 'b', 'c']

for x in list1:
print(x, len(x))

List = [4,5,6,7,8]

for i in List:
print(i)

for j in range(4,8):
print(j)

a = int(input())

for i in range(a):
print('',a)

a = int(input())
b = 1

while True:
if b != a:
print(b, b**2)
b += 1
else:
break

a = int(input())

for i in range(1, a+1):


print(i, i*i)

print(range(5))
print(list(range(5)))

for x in [1,2,3,4]:
if x % 3:
print(x)
else:
break
else:
print('end')

You might also like