Python Exercises - Part 1
Python Exercises - Part 1
2. Use the Print() method to print out a number (integer) of your choice
a. Add a comment that states what the two lines of code do
3. Add a comment that states which of the following lines will assign the value 365 to the
variable days_in_a_year
a. 365 = days_in_a_year
b. There are 365 days in a year
c. int days_in_a_year = 365
d. days_in_a_year = 365
e. int Days_in_a_year = 365
4. Write a program in Python that declares two variables, one storing a string value and
one an int value
a. Print out the string variable
b. Print out the integer value
c. Add a comment to your program to state what it does
5. Write a program in Python that stores the number of seconds in a minute, then print
out the value stored at this variable
a. Add a comment to state what the program does
6. Use the Print() method to print out the results to the following:
a. 49/7
b. 8*2
c. 34235+54654
d. 34654-9765
e. Make use of the four math operators writing equations of your own
7. Make use of two different relational operators, printing out the results
a. Add a multi-line comment that lists the other relational operators and
states what they do
Python Exercises – Part 1
8. Declare two variables in Python of your choice. Compare the two variables using both
of the equality operators, printing out the value.
a. Add a multi-line comment to state what this program does
9. Write a program in Python that prints out the number of seconds in a day. You must
make use of the variable that you declared as part of exercise 5.
a. Add a multi-line comment to explain what the program does
10. Write a program in Python that declares and assigns the variables length and width
with the values 18 and 7 respectively. Use these values to calculate and then print the
perimeter and area of a rectangle. You must store the two values in new variables.
12. As a comment, state what will be printed on screen from the following code:
marks = 25
print(marks)
13. As a comment, state what will be printed on screen from the following code:
marks = 25
mark = marks – 50
print(marks)
14. As a comment, state what will be printed on screen from the following code:
time_spent = 34
Python Exercises – Part 1
// after one minute
time_spent = time_spent+1
print(time_spent)
15. As a comment, state what the value of score would be after running the following
Python code:
score = 24
number_of_tries = 2
new_score = score * 2
16. As a comment, state what would be printed on the screen, and why, after running the
following Python code:
hours_in_a_week = hours_in_a_day * 7
hours_in_a_month = hours_in_a_week * 30
print(hours_in_a_month)
17. Write a program in Python that calculates the area of a circle. The program should use
two variables, both should be integer variables and one should be assigned the value
3.14. Print out the area of a circle with a radius of 6.
a. Store the area as a separate variable
b. Add a multi-line comment to explain what the program does