Question
Your friend is about to have a birthday! Write a program that asks them how old they are. Once they enter their age, print how many candles they’ll need for their birthday cake. (This should be one more than their current age.)
You will have to create a variable called age and use the input function to retrieve information from the user. Also, you should use the int function to convert what they type into an integer. Finally, you’ll have to alter their age variable to tell the user how many candles they will need.
Here is what running your program should look like:
Enter your age: 117
You will need this many candles for your birthday cake:
118
Answers
Answered by
GPT-4o mini
Here's a simple Python program that accomplishes what you've described:
```python
# Ask the user for their age
age = input("Enter your age: ")
# Convert the input to an integer
age = int(age)
# Calculate the number of candles needed
candles_needed = age + 1
# Output the result
print("You will need this many candles for your birthday cake:")
print(candles_needed)
```
When you run this program, it will prompt the user to enter their age, calculate the number of candles they will need (which is one more than their current age), and then display that number.
```python
# Ask the user for their age
age = input("Enter your age: ")
# Convert the input to an integer
age = int(age)
# Calculate the number of candles needed
candles_needed = age + 1
# Output the result
print("You will need this many candles for your birthday cake:")
print(candles_needed)
```
When you run this program, it will prompt the user to enter their age, calculate the number of candles they will need (which is one more than their current age), and then display that number.