[go: up one dir, main page]

0% found this document useful (0 votes)
12 views15 pages

Python Project - 240407 - 220903

Uploaded by

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

Python Project - 240407 - 220903

Uploaded by

dejeneleul158
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1

import math

radius = float(input("Enter the radius of the circle: "))

area = math.pi * radius**2

print("The area of the circle is:", area)

2.
fahrenheit = float(input("Enter the temperature in Fahrenheit: "))

celsius = (fahrenheit - 32) * 5 / 9

print("The temperature in Celsius is:", celsius)


3.
basic_salary = float(input("Enter Abebe's basic salary: "))
dearness_allowance = 0.4 * basic_salary
house_rent_allowance = 0.2 * basic_salary

gross_salary = basic_salary + dearness_allowance + house_rent_allowance

print("Abebe's gross salary is:", gross_salary)


4.
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")

full_name = last_name + " " + first_name

print("Reversed name: " + full_name)


5.
import math

radius = 6
volume = (4/3) * math.pi * radius**3

print("The volume of the sphere is:", volume)


6.
number = int(input("Enter a five-digit number: "))

# Extracting individual digits


digit_1 = number // 10000
digit_2 = (number // 1000) % 10
digit_3 = (number // 100) % 10
digit_4 = (number // 10) % 10
digit_5 = number % 10

# Calculating the sum of digits


digit_sum = digit_1 + digit_2 + digit_3 + digit_4 + digit_5

print("The sum of the digits is:", digit_sum)


7.
def add(x, y):
return x + y

def subtract(x, y):


return x - y

def multiply(x, y):


return x * y

def divide(x, y):


return x / y

print("Calculator Menu:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")

choice = int(input("Enter your choice (1-4): "))


if choice < 1 or choice > 4:
print("Invalid choice!")
else:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))

if choice == 1:
result = add(num1, num2)
operation = "+"
elif choice == 2:
result = subtract(num1, num2)
operation = "-"
elif choice == 3:
result = multiply(num1, num2)
operation = "*"
else:
result = divide(num1, num2)
operation = "/"
print("Result:", num1, operation, num2, "=", result)
8.
import cmath

a = float(input("Enter the coefficient a: "))


b = float(input("Enter the coefficient b: "))
c = float(input("Enter the coefficient c: "))

# Calculate the discriminant


discriminant = (b**2) - (4*a*c)

# Find two solutions


solution1 = (-b - cmath.sqrt(discriminant)) / (2*a)
solution2 = (-b + cmath.sqrt(discriminant)) / (2*a)

print("The solutions are:")


print("Solution 1:", solution1)
print("Solution 2:", solution2)
9.
name = input("Enter your name: ")
age = input("Enter your age: ")
address = input("Enter your address: ")

print("Name:", name)
print("Age:", age)
print("Address:", address)
10.
decimal = int(input("Enter a decimal number: "))

binary = bin(decimal)
octal = oct(decimal)
hexadecimal = hex(decimal)

print("Binary:", binary)
print("Octal:", octal)
print("Hexadecimal:", hexadecimal)
11
sum = 0
for i in range(0, 9):
term = 1 / (1 + i * 3)
sum += term

print("The sum of the sequence is:", sum)


12.
sum = 0

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


cube = i ** 3
sum += cube

print("The sum of the cubes of the first ten even natural numbers is:", sum)

13.
input_string = input("Enter a string: ")

output_string = input_string[0] # Initialize the output string with the first character
# Iterate through the input string starting from the second character
for i in range(1, len(input_string)):
if input_string[i] != input_string[i - 1]:
output_string += input_string[i]

print("Modified string:", output_string)

14.
input_text = input("Enter a text in an elaborated form: ")

words = input_text.split() # Split the input text into words

contracted_form = ""

# Iterate through the words and extract the first letter of each word
for word in words:
contracted_form += word[0]

print("Contracted form:", contracted_form.upper())


15.
try:
percentage = float(input("Please enter your percentage achieved in the class: "))

if percentage >= 93.33:


grade = "A"
elif percentage >= 90:
grade = "A-"
elif percentage >= 86.67:
grade = "B+"
elif percentage >= 83.33:
grade = "B"
elif percentage >= 80:
grade = "B-"
elif percentage >= 76.67:
grade = "C+"
elif percentage >= 73.33:
grade = "C"
elif percentage >= 70:
grade = "C-"
elif percentage >= 66.67:
grade = "D+"
elif percentage >= 63.33:
grade = "D"
elif percentage >= 60:
grade = "D-"
else:
grade = "F"

print("You earned a", grade, "in the class.")

except ValueError:
print("Invalid input. Please enter a valid percentage.")
16.
citizenship = input("Are you a citizen of
Ethiopia? (Enter 'yes' or 'no'): ")
years_of_residency = int(input("How many years have you lived in the locality? "))
endorsements = int(input("How many endorsements have you collected from the
electorate? "))

if citizenship.lower() == "yes" and years_of_residency >= 2 and endorsements >=


1000:
print("Congratulations! You are eligible to run for local assembly elections.")
else:
print("Sorry, you are not eligible to run for local assembly elections.")

17.
def is_prime(number):
if number <= 1:
return False
for i in range(2, int(number ** 0.5) + 1):
if number % i == 0:
return False

return True

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

if is_prime(num):
print(num, "is a prime number.")
else:
print(num, "is not a prime number.")
18.
for i in range(1, 8):
print('T' * i)

20 a
spaces = 6
stars = 1
for i in range(5):
print(" " * spaces + "*" * stars)
spaces -= 1
stars += 2
B.
size = 5

for i in range(size):
print(" " * (size - i - 1) + "*" * (2 * i + 1))

for i in range(size - 2, -1, -1):


print(" " * (size - i - 1) + "*" * (2 * i + 1))
Real b.
size = 5

for i in range(size):
print(" " * (size - i - 1) + "*" * (2 * i + 1))

for i in range(size - 2, -1, -1):


print(" " * (size - i - 1) + "*" * (2 * i + 1))
19.
numbers = input("Please enter a list of numbers, separated by spaces: ")
numbers_list = numbers.split()

count = len(numbers_list)
total = sum(float(num) for num in numbers_list)
average = total / count

print("There were", count, "numbers in the list.")


print("The average of the numbers was", average)

You might also like