0% found this document useful (0 votes)
6 views

Ict Python Programs

Uploaded by

vihaanshah199
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)
6 views

Ict Python Programs

Uploaded by

vihaanshah199
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/ 9

# 📌 Basic Arithmetic Programs

# Program: Addition of Two Numbers

a = int(input("Enter your first number: "))


b = int(input("Enter your second number: "))
print(a + b, "is your answer")

# Program: Calculation of Area of Rectangle

a = int(input("Enter your length: "))


b = int(input("Enter your breadth: "))
print(a * b, "is your area")

# Program: Simple Interest Calculation

a = int(input("Enter your principal: "))


b = int(input("Enter your rate: "))
c = int(input("Enter your time: "))
print((a * b * c) / 100, "is your simple interest")

# 📌 Comparison and Conditional Programs


# Program: Comparison of Two Numbers

a = int(input("Enter your first number: "))


b = int(input("Enter your second number: "))

if a > b:
print(a, "is the greater number")
elif b > a:
print(b, "is the greater number")
else:
print("Both your numbers are equal")

# Program: Profit or Loss Calculation

a = int(input("Enter your cost price: "))


b = int(input("Enter your sale price: "))
if a > b:
print(a - b, "is the loss incurred")
elif b > a:
print(b - a, "is the profit incurred")
else:
print("You have made no profit or loss")

# Program: Find the Greatest of Three Numbers

a = int(input("Enter your first number: "))


b = int(input("Enter your second number: "))
c = int(input("Enter your third number: "))

if a > b and a > c:


print(a, "is greater")
elif b > a and b > c:
print(b, "is greater")
else:
print(c, "is greater")

# 📌 Marks and Grading Programs


# Program: Pass or Fail Based on Marks

a = int(input("Enter your marks: "))

if a >= 40:
print("Congrats, you passed")
else:
print("Sorry, you failed")

# Program: Grading Based on Marks

a = int(input("Enter your marks: "))

if a >= 90:
print("Your Grade is an A*!")
elif a >= 80:
print("Your Grade is an A")
elif a >= 70:
print("Your Grade is a B")
elif a >= 60:
print("Your Grade is a C")
elif a >= 50:
print("Your Grade is a D")
elif a >= 40:
print("Your Grade is an E")
else:
print("Your Grade is a U")

# 📌 Temperature Classification
# Program: Temperature Classification

temp = int(input("Enter the temperature in degrees: "))

if temp >= 40:


print("The Temperature is Very Hot")
elif temp > 30:
print("The Temperature is Hot")
elif temp > 20:
print("The Temperature is Pleasant")
elif temp >= 10:
print("The Temperature is Cold")
else:
print("The Temperature is Very Cold")

# 📌 Loops and Number Printing


# Program: Printing Numbers from 1 to 10

for i in range(1, 11):


print(i)

# Program: Printing Even Numbers from 2 to 10

for i in range(2, 11, 2):


print(i)

# Program: Printing Odd Numbers from 1 to 10

for i in range(1, 11, 2):


print(i)

# Program: Printing Numbers from 1 to 10 using `while` Loop

i=1
while i < 11:
print(i)
i += 1

# 📌 Loop with Summation


# Program: Sum of Numbers Until 0 is Entered

sum = 0
i = int(input("Enter a number. Enter 0 to stop: "))

while i != 0:
sum += i
print("Current sum:", sum)
i = int(input("Enter a number: "))

# Program: Sum of First N Natural Numbers

n = int(input("Enter the number up to which you want the sum: "))


sum = 0

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


sum += i

print("The sum of", n, "natural numbers is", sum)

# 📌 Multiplication Table
# Program: Multiplication Table of a Number

n = int(input("Enter the number you want the table of: "))


for i in range(1, 11):
print(n, "*", i, "=", n * i)
# 📌 Guessing Game
# Program: Guess the Secret Number

secret = 20
guess = int(input("Enter your guessed number: "))

while guess != secret:


print("Guess incorrect! Please try again.")
guess = int(input("Enter guess again: "))

print("Congratulations! You guessed correctly.")

# 📌 Jump Statements
# Jump Statement - break

for i in range(1, 101):


num = int(input("Enter a number: "))
if num > 0:
print(num)
else:
print("Negative number detected, exiting program.")
break

# Jump Statement - continue

for i in range(1, 101):


if i % 3 != 0:
print(i)
else:
continue

# 📌 Temperature Average Calculation


# Program: Average Temperature Over N Days

n = int(input("Enter number of days to calculate average temperature: "))


total = 0
for i in range(1, n + 1):
temp = int(input(f"Enter temperature for day {i}: "))
total += temp

avg = total / n
print("Average Temperature is", avg, "°")

# Program: Skip printing the number if it is 7

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

for i in range(10):
if n == 7:
continue
else:
print(n)

ICT HW PROGRAMS
Program 1
a = int(input("Enter your marks: "))​
if a >= 90:​
​ print("Your Grade is an A!")​
elif a >= 80:​
​ print("Your Grade is an B")​
elif a >= 70:​
​ print("Your Grade is a C")​
elif a >= 60:​
​ print("Your Grade is a D")​
else:​
​ print("Your Grade is an F")

Program 2
temp = int(input("Enter the temperature in degrees: "))​
if temp > 30:​
​ print("It's too hot! Stay indoors.")​
elif temp >= 20:​
​ print("It's a nice day")​
elif temp < 20:​
​ print("It's cold! Wear a jacket.")

Program 4
n = int(input("Enter the number up to which you want the sum: "))​
sum = 0​
for i in range(1, n + 1):​
​ sum = sum + i​
print("The sum of", n, "natural numbers is", sum)

Program 5
for i in range(10, 0, -1):​
​ print(i)​
print("Time's up!")

Program 6
n = int(input("Enter the number you want in the table: "))​
for i in range(1, 11):​
​ print(n, "*", i, "=", n * i)

Program 7
n = 13 ​
an = int(input("Guess the secret number (between 1 and 20): "))​

while an != n:​
​ if an < 1 or an > 20:​
​ print("Please enter a number between 1 and 20.")​
​ elif an < n:​
​ print("Too low! Try again.")​
​ elif an > n:​
​ print("Too high! Try again.")​
​ an = int(input("Enter guess again: "))​

print("Congratulations! You guessed it!")

Program 8
an = 3243​
n = int(input("Enter your guessed number: "))​
while an != n:​
​ print("Pin is incorrect! Please try again")​
​ n = int(input("Enter new attempt: "))​
print("Access Granted")

Program 9
an = 3243​
n = int(input("Enter your guessed number: "))​
while an != n:​
​ print("Pin is incorrect! Please try again.")​
​ if n < an:​
​ print("Too low! Try again.")​
​ else:​
​ print("Too high! Try again.")​
​ n = int(input("Enter new attempt: "))​
print("Congratulations! Your Pin is correct.")

Program 10
cp = "PythonRocks"​
a = 0​
ma = 3​
while a < ma:​
​ p = input("Enter your password: ")​
​ if p == cp:​
​ print("Access Granted!")​
​ break​
​ else:​
​ a += 1​
​ print("Incorrect password. Please try again.")​
if a == ma:​
​ print("Account Locked!")

Program 11
for i in range(2, 21, 2):​
​ print(i)

Program 12
num = 0 ​
while num >= 0: ​
​ try:​
​ num = float(input("Enter a number (negative to stop): "))​
​ if num < 0:​
​ print("Negative number detected. Exiting!")​
​ except ValueError:​
​ print("Invalid input. Please enter a valid number.")

Program 13
while 1:​
​ user_input = input("Enter a number: ")​
​ if user_input == 'exit':​
​ print("Exiting the program.")​
​ break​
​ number = int(user_input)​
​ if number % 7 == 0:​
​ print("First multiple of 7 found:", number)​
​ break

Program 14
name = input("Please enter your name:\n")​
age = int(input("What is your age?\n"))​
tv_show = input("What is your favourite TV programme?\n")​
print(f"{name} is {age} years old and likes {tv_show}")

Program 15
print("Rectangle 1")​
length1 = int(input("Please enter the length:\n"))​
width1 = int(input("Please enter the width:\n"))​
area1 = length1 * width1​

print("\nRectangle 2")​
length2 = int(input("Please enter the length:\n"))​
width2 = int(input("Please enter the width:\n"))​
area2 = length2 * width2​

if area1 > area2:​
​ print("\nRectangle 1 has the largest area")​
elif area2 > area1:​
​ print("\nRectangle 2 has the largest area")​
else:​
​ print("\nBoth rectangles have the same area")

You might also like