ICT Complete Assignment
ICT Complete Assignment
ASSIGNMENT NO 1
NAME : NOSHAIRWAN HAIDER
CMS ID : 507575
CLASS : EE 16 -A
1. Write a Python program that prints the numbers from 1 to 50, but:
For multiples of 3, print "Fizz" instead of the number.
For multiples of 5, print "Buzz" instead of the number.
For multiples of both 3 and 5, print "FizzBuzz".
SOL :
for a in range(1, 51):
if a % 3 == 0:
print("Fizz")
elif a % 5 == 0:
print("Buzz")
elif a % 3 == 0 and a % 5 == 0:
print("FizzBuzz")
else:
print(a)
2) Ask the user to input a number. Write a Python program to check if the number is a prime number
or not.
The program should use a loop to check divisibility and condition statements to
determine primality.
Solution :
try:
number = int(user_input)
is_prime = True
if number < 2:
is_prime = False
else:
for i in range(2, number):
if number % i == 0:
is_prime = False
break
if is_prime:
print(number, "is a prime number.")
else:
print(number, "is not a prime number.")
except ValueError:
print("Please enter a valid number.”)
3) write a Python program that takes an input n and prints the following pattern:
1
12
123
1234
...
SOL :
n = int(input("Enter the number of rows: "))
for i in range(1, n + 1):
4) Set a secret number in your code (e.g., secret_number = 7). Write a program that asks
the user to guess the number and provides feedback:
If the guess is too low, print "Too low, try again!"
If the guess is too high, print "Too high, try again!"
The loop should continue until the user guesses the correct number.
SOL:
secret_number = 67
while True:
5) Ask the user to input a string. Write a program that counts how many vowels (a, e, i, o,
u) are in the string.
SOL :
user_string = input("Enter a string: ")
vowel_count = 0
vowels = "aeiou"
for char in user_string:
if char in vowels:
vowel_count = vowel_count + 1
NOTE :
This assignment is been submitted late as I was suffering from
“dengue” due to which I was on complete bed rest. It is
requested to accept my late submission taking consideration of
my dieseas . Test and docter prescription are attached bellow