###Print Functions
Hello, World!
Solution:
print("Hello, World!")
name
and age
, and print them using the print
function. Use the variables to print the following:
My name is John and I am 25 years old.
Solution:
name = "John"
age = 25
print("My name is", name, "and I am", age, "years old.")
name
and age
:
My name is John and I am 25 years old.
Solution:
name = "John"
age = 25
print(f"My name is {name} and I am {age} years old.")
def greet(name):
print(f"Hello, {name}!")
greet("Alice")
Solution:
def greet(name):
print(f"Hello, {name}!")
greet("Alice")
Solution:
number = int(input("Enter a number: "))
if number > 0:
print("The number is positive.")
elif number < 0:
print("The number is negative.")
else:
print("The number is zero.")
name = "Alice"
age = 30
print(f"{name} is {age} years old.")
Solution:
# Assign the string "Alice" to the variable 'name'
name = "Alice"
# Assign the integer 30 to the variable 'age'
age = 30
# Print the name and age using an f-string
print(f"{name} is {age} years old.")
def add(a, b):
return a + b
result = add(3, 5)
print(result)
Solution:
"""
This program defines a function 'add' that takes two arguments 'a' and 'b'
and returns their sum. It then calls this function with the arguments 3
and 5, stores the result in the variable 'result', and prints the result.
"""
def add(a, b):
return a + b
result = add(3, 5)
print(result)