0% found this document useful (0 votes)
11 views8 pages

Range 1 11 Print: For in

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)
11 views8 pages

Range 1 11 Print: For in

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
You are on page 1/ 8

for i in range(1, 11):

print(i)

1
2
3
4
5
6
7
8
9
10

i = 2
while i <= 20:
print(i)
i += 2

2
4
6
8
10
12
14
16
18
20

for i in range(1, 6):


print(i**2)

1
4
9
16
25

word = input("Enter a word: ")


for letter in word:
print(letter)

Enter a word: hii

h
i
i

for _ in range(5):
print("Hello")
Hello
Hello
Hello
Hello
Hello

i = 10
while i >= 1:
print(i)
i -= 1

10
9
8
7
6
5
4
3
2
1

num = int(input("Enter a number: "))


for i in range(1, 11):
print(num * i)

Enter a number: 4

4
8
12
16
20
24
28
32
36
40

total = 0
for i in range(1, 101):
total += i
print("Sum: ", total)

Sum: 5050

n = int(input("Enter a number: "))


fact = 1
for i in range(1, n+1):
fact *= i
print("Factorial: ", fact)
Enter a number: 2

Factorial: 2

for i in range(1, 11):


if i == 5:
continue
print(i)

1
2
3
4
6
7
8
9
10

text = input("Enter a string: ")


vowels = 'aeiouAEIOU'
count = 0
for ch in text:
if ch in vowels:
count += 1
print("Vowel count: ", count)

Enter a string: jgdhsjdhsjxgcskjxalgdwdgwhdjkgwdhkahdsu

Vowel count: 3

num = int(input("Enter a number: "))


if num < 2:
print("Not Prime")
else:
for i in range(2, int(num**0.5)+1):
if num % i == 0:
print("Not Prime")
break
else:
print("Prime")

Enter a number: 8973587589

Not Prime

for i in range(1, 6):


print("*" * i)

*
**
***
****
*****

n = int(input("Enter number of terms: "))


a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b

Enter number of terms: 4

0 1 1 2

num = int(input("Enter a number: "))


rev = 0
while num > 0:
rev = rev * 10 + num % 10
num //= 10
print("Reversed number:", rev)

Enter a number: 45665432

Reversed number: 23456654

num = int(input("Enter a number: "))


total = 0
while num > 0:
total += num % 10
num //= 10
print("Sum of digits:", total)

Enter a number: 3445

Sum of digits: 16

text = input("Enter a string: ")


char = input("Enter character to count: ")
count = 0
for c in text:
if c == char:
count += 1
print(f"'{char}' appears {count} times.")

Enter a string:
fehjqkjdjksahxsadhmskjdjksdghsmcdwdgvwshgdhwdghwgwdgdwliuedgwdkjgilwfq
ghfqdwhdwqfehjdehjerhjerqhjewqhewqh
Enter character to count: c

'c' appears 1 times.

for i in range(1, 11):


for j in range(1, 11):
print(f"{i} x {j} = {i*j}")
print()

1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5
1 x 6 = 6
1 x 7 = 7
1 x 8 = 8
1 x 9 = 9
1 x 10 = 10

2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20

3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30

4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60

7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70

8 x 1 = 8
8 x 2 = 16
8 x 3 = 24
8 x 4 = 32
8 x 5 = 40
8 x 6 = 48
8 x 7 = 56
8 x 8 = 64
8 x 9 = 72
8 x 10 = 80

9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81
9 x 10 = 90

10 x 1 = 10
10 x 2 = 20
10 x 3 = 30
10 x 4 = 40
10 x 5 = 50
10 x 6 = 60
10 x 7 = 70
10 x 8 = 80
10 x 9 = 90
10 x 10 = 100

numbers = [1, 4, 7, 10, 13, 16, 19]


for num in numbers:
if num % 2 != 0:
print(num)

1
7
13
19

nums = []
for _ in range(5):
n = int(input("Enter number: "))
nums.append(n)
print("Max:", max(nums))
print("Min:", min(nums))

Enter number: 32
Enter number: 36
Enter number: 67
Enter number: 90
Enter number: 98

Max: 98
Min: 32

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


for j in range(1, i + 1):
print(j, end="")
print()

1
12
123
1234
12345
text = input("Enter a string: ")
rev = ""
for ch in text:
rev = ch + rev
if text == rev:
print("Palindrome")
else:
print("Not Palindrome")

Enter a string: dhdhbekbrkhrlrrhddjhhrjr

Not Palindrome

You might also like