For Loop Coding Practice 9b.python
For Loop Coding Practice 9b.python
n=int(input())
m=int(input())
for i in range(1, n+1):
if i%m==0:
print(i)
Input:10, 3
Output:
3
6
9
n=int(input())
t=int(input())
count=0
for i in range(1, n+1):
if i%t==0:
count=count+1
print(count)
Input:12, 13
Output:4
Count of Vowels:------------------------------------------------
s=input()
count=0
for i in s:
if (i=="a") or (i=="e") or (i=="i") or (i=="o") or (i=="u") :
count=count+1
print(count)
n=int(input())
for i in range(1, n+1):
if i%2==0 and i%3==0:
print(i)
Input:15
Output:6, 12
s=input()
for i in s:
if i=="a" or i =="z":
print(i)
Input :zigzag
Output :z, z, a
s=input()
len_s=len(s)
for i in range(1, len_s+1):
n=len_s-i
print(s[n])
Input: scale
Output: e, l, a, c, s
m=int(input())
n=int(input())
total_numbers=n-m
emp=""
for i in range(total_numbers+1):
num=n-i
if num%2==1:
emp=emp+str(num)+" "
print(emp)
Input:1, 10
Output:9 7 5 3 1
n=int(input())
for i in range(n):
m=n-i
m=m*"* "
print(m)
n = int(input())
print(row)
Input:4
Output:
* * * *
* * *
* *
*
n=int(input())
for i in range(1, n+1):
print(i*"* ")
for i in range(n):
print((n-i)*"* ")
Input:3
Output:
*
* *
* * *
* * *
* *
*
n=int(input())
print(n*"* ")
for i in range(1, n):
print((n-i)*"+ ")
Input:4
Output:
* * * *
+ + +
+ +
+
m=int(input())
n=int(input())
product=1
for i in range(m, n+1):
if i%3==0:
product=product*i
if True:
print(product)
else:
print(1)
( or )
m=int(input())
n=int(input())
product=1
for i in range(m, n+1):
if i%3==0:
product*=i
print(product)
Input:2, 7
Output:18
Sum of K powers:------------------------------------------------
n=int(input())
k=int(input())
sum=0
for i in range(1, n+1):
m=i**k
sum=sum+m
print(sum)
Input:5, 3
Output:225
n=int(input())
count=0
for i in range(1, n+1):
if i%6==0 and i%8==0:
count+=1
print(count)
Input:50
Output:2
n=int(input())
m=int(input())
print(pow(n, m))
( or )
n=int(input())
m=int(input())
p=1
for _ in range(m):
p*=n
print(p)
Input:2, 3
Output:8
m=int(input())
n=int(input())
product=1
for i in range(m, n+1):
product*=i
print(product)
Input:2, 5
Output:120
-----------------------------------------------------------------------------------
---------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------
Multiplication Table:
n=int(input())
for i in range(1, 11):
print(str(n) + " x "+str(i)+ " = "+str(i*n))
Input:3
Output:
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
Vowels in a String:---------------------------------------------
s=input()
emp=""
for i in s:
if i=="a" or i=="e" or i=="i" or i=="o" or i=="u":
emp+=i
print(emp)
Input: container
Output: oaie
s=input()
len_s=len(s)
emp=""
for i in range(1, len_s+1):
n=len_s-i
emp+=s[n]
print(emp)
Sum Of K Powers-2:----------------------------------------------
n=input()
len_n=len(n)
sum=0
for i in range(len_n):
sum+=int(n[i])**len_n
print(sum)
Input:24753
Output:21231
Armstrong Number:-----------------------------------------------
n=int(input())
len_n=len(str(n))
sum=0
for i in str(n):
sum+=int(i)**len_n
if sum==n:
print("Armstrong Number")
else:
print("Not an Armstrong Number")
Input:54748
Output: Armstrong Number
Factors of a Number:--------------------------------------------
n=int(input())
for i in range(1, n+1):
if n%i==0:
print(i)
Input:6
Output:1, 2, 3, 6
Factors of a Number-2:------------------------------------------
n=int(input())
result=""
for i in range(1, n+1):
factors=n%i==0
if factors:
result+=str(i)+" "
print(result)
Input:15
Output:1 3 5 15
n=int(input())
sum=0
for i in range(1, n+1):
factors=n%i==0
if factors:
sum+=i
print(sum)
Input:12
Output:28
Greatest Among N Numbers:---------------------------------------
n=int(input())
first_input=int(input())
greatest_number=first_input
for i in range(n-1):
number=int(input())
if number>greatest_number:
greatest_number=number
print(greatest_number)
Perfect Number:-------------------------------------------------
n=int(input())
sum=0
for i in range(1, n):
if n%i==0:
sum+=i
if sum==n:
print("Perfect Number")
else:
print("Not a Perfect Number")
Input:6
Output: Perfect Number
m = int(input())
n = int(input())
total_digits_count = 0
for number in range(m, n + 1):
digits_count = len(str(number))
total_digits_count = total_digits_count + digits_count
print(total_digits_count)
Input:4, 13
Output:14
Divisible by 6--------------------------------------------------
m = int(input())
n = int(input())
count = 0
numbers_divisible_by_6 = ""
for number in range(m, n + 1):
if number % 6 == 0:
count = count + 1
numbers_divisible_by_6 = numbers_divisible_by_6 + str(number) + (" ")
if count == 0:
print("No Numbers Found")
else:
print(numbers_divisible_by_6)
Input:6, 23
Output:6, 12, 18
Vowels of a String:---------------------------------------------
string = input()
vowels_count = 0
for character in string:
is_vowel = (character == "a") or (character == "e") or (character == "i") or
(character == "o") or (character == "u")
if is_vowel:
vowels_count = vowels_count + 1
if vowels_count > 2:
print("String has more than two vowels")
else:
print("String doesn't have more than two vowels")
Indivisible Number:---------------------------------------------
n=int(input())
is_divisible=False
for i in range(2, 10):
if n%i==0:
is_divisible=True
if is_divisible:
print("Divisible Number")
else:
print("Indivisible Number")
n = int(input())
first_input = int(input())
smallest_number = first_input
for i in range(n - 1):
number = int(input())
if number < smallest_number:
smallest_number = number
print(smallest_number)
Divisible by 9 in a range:--------------------------------------
m = int(input())
n = int(input())
count = 0
numbers_divisible_by_9 = ""
for number in range(m, n + 1):
if number % 9 == 0:
count = count + 1
numbers_divisible_by_9 = numbers_divisible_by_9 + str(number) + (" ")
if count == 0:
print("No Numbers found")
else:
print(numbers_divisible_by_9)
----------------------------------------------------------------
n = int(input())
for i in range(1, n + 1):
term = ("2") * i
term = int(term)
print(term)
n = int(input())
term_number = "2"
total = 0
for i in range(1, n+1):
term = term_number * i
total = total + int(term)
print(total)
Input:3
Output:246
n = int(input())
term_number = "1"
sum_of_terms = 0
for i in range(1, n + 1):
term = term_number * i
sum_of_terms = sum_of_terms + int(term)
print(sum_of_terms)
Input:4
Output:1234
x = int(input())
n = int(input())
sum_of_terms = 0
for i in range(1, n + 1):
term = str(x) * i
sum_of_terms = sum_of_terms + int(term)
print(sum_of_terms)
Input:7, 4
Output:8638
x = int(input())
n = int(input())
sum_of_terms = 0
for i in range(1, n + 1):
number = str(x) * i
term = int(number) ** 2
sum_of_terms = sum_of_terms + term
print(sum_of_terms)
Input:4, 3
Output:199088