0% found this document useful (0 votes)
11 views3 pages

Python Exercises for Beginners

Uploaded by

mahghe
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)
11 views3 pages

Python Exercises for Beginners

Uploaded by

mahghe
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

‭Python beginner exercises‬

‭●‬ ‭Hello, World!‬


‭Write a Python program that prints the message "Hello, World!" to the console.‬

‭●‬ ‭Personal Information‬


‭ reate variables to store your name, age, and favorite color.‬
C
‭Print a message that displays your personal information using these variables.‬

‭●‬ ‭Calculator‬
‭ sk the user to input two numbers.‬
A
‭Store these numbers in variables.‬
‭Calculate and print the sum, difference, product, and quotient of these two numbers.‬

‭●‬ ‭String Concatenation‬


‭ reate two variables, first_name and last_name, and assign your first and last names to‬
C
‭them.‬
‭Use string concatenation to combine these variables and print your full name.‬

‭●‬ ‭Data Type Exploration‬


‭ eclare variables with different data types (integer, float, string, and boolean).‬
D
‭Use the type() function to print the data type of each variable.‬

‭●‬ ‭Age Calculator‬


‭ sk the user to input their birth year.‬
A
‭Calculate and print their current age based on the current year.‬

‭●‬ ‭Temperature Converter‬


‭ sk the user to input a temperature in Celsius.‬
A
‭Convert the temperature to Fahrenheit using the formula (celsius * 9/5) + 32.‬
‭Print the temperature in Fahrenheit.‬

‭●‬ ‭Area of a Circle‬


‭ sk the user to input the radius of a circle.‬
A
‭Calculate and print the area of the circle using the formula area = π * radius^2 (you can use‬
‭3.14 as an approximation for π).‬

‭●‬ ‭Grocery List‬


‭ reate a list of grocery items.‬
C
‭Print each item in the list on a new line.‬
‭●‬ ‭Fizz Buzz‬
‭ rite a program that prints the numbers from 1 to 100.‬
W
‭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" instead of the number.‬
‭Suggested solutions‬

‭ .‬ ‭Hello, World!‬
1
‭python‬
‭Solution‬
print‬
‭ (‭
‭"‬Hello, World!"‬
)‬

‭ .‬ ‭Personal Information‬
2
‭python‬
‭Solution‬
‭ame =‬‭
n "Alice"‬
age =‬‭
‭ 13‬
favorite_color =‬‭
‭ "Blue"‬
print‬
‭ (‭
‭"‬My name is"‬
, name,‬‭
‭ "and I'm"‬
, age,‬‭
‭ "years old.‬‭
My favorite color‬
is"‬
‭ , favorite_color)‬

‭ .‬ ‭Calculator‬
3
‭python‬
‭Solution‬
‭um1 =‬‭
n float‬
(‭
‭i‬nput‬(‬
‭ "Enter the first number: "‬
‭ ))‬

num2 =‬‭
‭ float‬
(‭
‭i‬nput‬(‬
‭ "Enter the second number: "‬
‭ ))‬

sum‬‭
‭ = num1 + num2‬
difference = num1 - num2‬

product = num1 * num2‬

quotient = num1 / num2‬

print‬
‭ (‭
‭"‬Sum:"‬
,‬‭
‭ sum‬
)‬

print‬
‭ (‭
‭"‬Difference:"‬ , difference)‬

print‬
‭ (‭
‭"‬Product:"‬, product)‬

print‬
‭ (‭
‭"‬Quotient:"‬, quotient)‬

‭ .‬ ‭String Concatenation‬
4
‭python‬
‭Solution‬
‭irst_name =‬‭
f "Alice"‬
last_name =‬‭
‭ "Smith"‬
full_name = first_name +‬‭
‭ " "‬‭
+ last_name‬
print‬
‭ (‭
‭"‬Full Name:"‬
, full_name)‬

‭ .‬ ‭Data Type Exploration‬


5
‭python‬
‭Solution‬
‭um =‬‭
n 10‬
pi =‬‭
‭ 3.14‬
name =‬‭
‭ "Python"‬
is_cool =‬‭
‭ True‬
print‬
‭ (‭
‭"‬Type of num is:"‬,‬‭
‭ type‬ (num))‬

print‬
‭ (‭
‭"‬Type of pi is:"‬
,‬‭
‭ type‬ (pi))‬

print‬
‭ (‭
‭"‬Type of name is:"‬,‬‭
‭ type‬ (name))‬

print‬
‭ (‭
‭"‬Type of is_cool is:"‬ ,‬‭
‭ type‬(is_cool))‬

You might also like