Take two inputs from the user. One will be an integer. The other will be a float number. Then multiply them to display the output.
Hint: Use input() to take user input. By default, input returns a string. Use int() and float() to convert those inputs to numeric types, and then multiply them.
int_num = int(input("Give me an integer number: "))
float_num = float(input("Give me a float number: "))
result = int_num * float_num
print("Your result is:", result)
Take two numbers from the users. Calculate the result of second number power of the first number.
Hint: To raise a number to a power, use two asterisks (**). For example, 4**3 gives you 64.
base_num = int(input('Give me the base number: '))
power_num = int(input('Give me the power number: '))
result = base_num ** power_num
print('Your result is:', result)
Find the largest of the three numbers entered by the user.
Hint: Ask the user to enter three numbers. You can assume the first number is the largest and then check if the second or third number is larger. Or use max().
num1 = int(input("First number: "))
num2 = int(input("Second number: "))
num3 = int(input("Third number: "))
largest = max(num1, num2, num3)
print("Largest number you entered is:", largest)
Take multiple numbers as input from the user in a single line and calculate the average.
Hint: Ask the user to input numbers separated by spaces. Use split() then convert to numbers.
numbers = input("Enter numbers separated by spaces: ").split()
numbers = [float(num) for num in numbers]
total = sum(numbers)
count = len(numbers)
average = total / count
print("The average is:", average)
Take the lengths of the three sides of a triangle from the user and calculate the area (Heron's formula).
import math
a = float(input("Enter side a: "))
b = float(input("Enter side b: "))
c = float(input("Enter side c: "))
s = (a + b + c) / 2
area = math.sqrt(s * (s - a) * (s - b) * (s - c))
print("The area of the triangle is:", area)
Take the principal amount, annual interest rate, and duration in years as input. Compute the compound interest.
Hint:Amount = P*(1 + r/100)^t, then CI = Amount - P.
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the annual interest rate (in %): "))
time = float(input("Enter the duration in years: "))
amount = principal * (1 + rate / 100) ** time
compound_interest = amount - principal
print("Compound Interest is:", compound_interest)
Take marks and their corresponding weights as input and calculate the weighted average mark.
marks = input("Enter marks separated by spaces: ").split()
weights = input("Enter corresponding weights separated by spaces: ").split()
marks = [float(m) for m in marks]
weights = [float(w) for w in weights]
total_weighted_score = sum(m * w for m, w in zip(marks, weights))
total_weight = sum(weights)
weighted_average = total_weighted_score / total_weight
print("The weighted average mark is:", weighted_average)
Create all possible sentences by combining one word from each of three lists.
list1 = ["I", "You"]
list2 = ["like", "love"]
list3 = ["Python", "programming"]
for w1 in list1:
for w2 in list2:
for w3 in list3:
print(f"{w1} {w2} {w3}")
Generate a random password with at least one uppercase, one lowercase, one digit, and one special character.
secret_word = "hello"
guessed = ["_" if c != "e" else "e" for c in secret_word]
while "_" in guessed:
print("Current word:", " ".join(guessed))
guess = input("Guess a letter: ").lower()
if guess in secret_word:
for i, c in enumerate(secret_word):
if c == guess:
guessed[i] = guess
else:
print("Wrong guess. Try again!")
print("Congratulations! The word was:", secret_word)
Filter employees where age > 30 and salary > 70,000.