Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Programming Practice-Problem Questions and Detailed Solutions - Volume 3 (Conversion, Measurement, and Unit Exercises)
Description: The document consists of Python programming problems and exercises as well as the detailed solution and explanation for each practice question.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


PROGRAMMING PRACTICE-PROBLEM QUESTIONS AND
DETAILED SOLUTIONS – VOLUME 3
CONVERSION, MEASUREMENT, AND UNIT EXERCISES

1

Contents
1

Problem to Convert Other Time Units to Seconds
...
1

Program
...
2

Output
...
4

2
...
4

2
...
4

3

Problem to Display Current Time
...
1

Program
...
2

Output
...
5

4
...
5

4
...
6

5

Problem to Add All the Digits in an Integer Number
...
1

Program
...
2

Output
...
Your program should be able to add them together to give a duration
summation in seconds
...
1 Program
weeks = int(input("Please enter the number of weeks:\n"))
days = int(input("Now, enter the number of days:\n"))
hours = int(input("Enter the number of hours:\n"))
minutes = int(input("Enter the number of minutes:\n"))
seconds = int(input("Please enter the number of seconds:\n"))

minutes_to_seconds = minutes * 60
#Recall that there are 60 seconds in a minute
hours_to_seconds = hours * 60 * 60
#Recall that there are 60 minutes in an hour
days_to_seconds = days * 24 * 60 * 60
#Recall that there are 24 hours in a day
weeks_to_seconds = weeks * 7 * 24 * 60 * 60
#Recall that there are 7 days in a week
total_seconds = weeks_to_seconds
minutes_to_seconds + seconds

+

days_to_seconds

+

hours_to_seconds

print("The total number of seconds is " + str(total_seconds) " seconds
...
2 Output
Please enter the number of weeks:
3
Now, enter the number of days:
6
Enter the number of hours:
10
Enter the number of minutes:
55
Please enter the number of seconds:
31
The total number of seconds is 2372131 seconds
...
This problem is a reversal of the
procedure in the preceding problem
...


2
...
2 Output
Enter the number of seconds to convert:
2372131
There are 3 weeks, 6 days, 10 hours, 55 minutes, and 31 seconds in 2372131

4

3

Problem to Display Current Time
Write a computer program that will output the current date and time
...
There are in-built functions that can detect and read the computer
system’s clock to produce output in forms that are human understandable
...
1 Program
from datetime import datetime
#from is a keyword used with a module where the class is imported
#import lets the class datetime to be used later
current_date_and_time = datetime
...
strftime("%d/%m/%Y %H:%M:%S")
#strftime is used to format the date in specific and more human friendly and readable ways
print("This is a formatted current date and time: " + str(formatted))
month_formatted = current_date_and_time
...
2 Output
The current date and time is 2023-03-17 16:43:50
...
That is, it should be able to read inputs from
degrees Celsius to degrees Fahrenheit, likewise from degrees Fahrenheit to degrees Celsius
...
1 Program
#1
...
From degrees Fahrenheit to degrees Celsius
fahrenheit = float(input("Please enter the temperature value in degrees Fahrenheit:\n"))
celsius = (fahrenheit - 32) * (5/9)
print("The temperature in degrees Celsius is " + str(celsius))

4
...
0
Please enter the temperature value in degrees Fahrenheit:
95
The temperature in degrees Celsius is 35
...
For instance, an integer 42843 should have an expected output
of 4+2+8+4+3 = 21
...
1 Program
number = list(input("What is the 5-digit integer?\n"))
#Note that the input was not read in the usual familiar ways with integer data type as in the
previous examples
...
List is a versatile data type that can store varieties of
many data types
...

#[] allows each item in the list to be indexed starting from 0
print("The sum of the digits is " + str(sum_of_digits))

5
Title: Programming Practice-Problem Questions and Detailed Solutions - Volume 3 (Conversion, Measurement, and Unit Exercises)
Description: The document consists of Python programming problems and exercises as well as the detailed solution and explanation for each practice question.