0% found this document useful (0 votes)
2 views2 pages

Simple Calculator Create A Program That Takes Two Numbers From The User and Prints Their Sum - 030609

The document contains a series of Python programming exercises aimed at beginners. It includes tasks such as creating a simple calculator, determining if a number is even or odd, converting human age to dog years, and implementing a number guessing game. Additional exercises involve generating multiplication tables, printing triangles, summing digits, reversing strings, and converting temperatures from Celsius to Fahrenheit.

Uploaded by

zouaoui ouerda
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)
2 views2 pages

Simple Calculator Create A Program That Takes Two Numbers From The User and Prints Their Sum - 030609

The document contains a series of Python programming exercises aimed at beginners. It includes tasks such as creating a simple calculator, determining if a number is even or odd, converting human age to dog years, and implementing a number guessing game. Additional exercises involve generating multiplication tables, printing triangles, summing digits, reversing strings, and converting temperatures from Celsius to Fahrenheit.

Uploaded by

zouaoui ouerda
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/ 2

.

Simple Calculator Create a program that takes two numbers from the user and prints
their sum.

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
print("The sum is:", num1 + num2)

3. Even or Odd

Write a Python program that asks the user for a number and tells them whether it’s even or
odd.

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


if num % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")

4. Age in Dog Years Ask the user for their age and tell them how old they are in dog years
(1 human year = 7 dog years).

human_age = int(input("Enter your age: "))


dog_years = human_age * 7
print("Your age in dog years is:", dog_years)

5. Simple Number Guessing Game

Write a program that randomly chooses a number between 1 and 10 and asks the user to guess
the number.

import random

secret_number = random.randint(1, 10)


guess = int(input("Guess a number between 1 and 10: "))

if guess == secret_number:
print("You guessed it right!")
else:
print(f"Wrong! The secret number was {secret_number}.")

6. Multiplication Table

Create a program that asks the user for a number and prints the multiplication table for that
number.

num = int(input("Enter a number to print its multiplication table: "))


for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
7. Print a Triangle

Write a program that prints a triangle of stars (*) based on a number the user inputs. For
example, if the user enters 5, it should print:

**
***
****
*****
rows = int(input("Enter the number of rows for the triangle: "))
for i in range(1, rows + 1):
print("*" * i)

8. Sum of Digits

Ask the user for a number and calculate the sum of its digits.

number = input("Enter a number: ")


digit_sum = sum(int(digit) for digit in number)
print("The sum of the digits is:", digit_sum)

9. Reverse a String

Write a program that asks the user for a word and prints the word in reverse order.

word = input("Enter a word: ")


print("Reversed word:", word[::-1])

10. Temperature Converter

Write a program that converts temperature from Celsius to Fahrenheit.

celsius = float(input("Enter temperature in Celsius: "))


fahrenheit = (celsius * 9/5) + 32
print(f"{celsius}°C is equal to {fahrenheit}°F")

You might also like