Wednesday, November 16, 2022

Strings and Variables 1 - Python Programming for Beginners Practice Exercise

Exercise 1:

Write a Python program that uses three variables. The variables in your program will be animal, vegetable, and mineral. Assign a string value to each one of the variables. Your program should display "Here is an animal, a vegetable, and a mineral." Next, display the value for animal, followed by vegetable, and finally mineral. Each one of the values should be printed on their own line. Your program will display four lines in total.

Sample Output:

Here is an animal, a vegetable, and a mineral.

dog

tomato

gold

Solution:

#!/usr/bin/env python3
animal = 'dog'
vegetable = 'tomato'
mineral = 'gold'

print('Here is an animal, a vegetable, and a mineral.')
print(animal)
print(vegetable)
print(mineral)

No comments:

Post a Comment