Relative Content

Tag Archive for pythonstringplaceholder

Speed Policing Programming Exercise

The program prompts for two floats. The police’s ability to input numbers via keyboard has severely deteriorated due to excessive smartphone use so it’s best for everyone that we give nice notifications about invalid inputs. In case the police accidentally inputs proper floats, the program should print the given numbers and the calculated speed as kilometers per hour. As you can see from the examples, all numbers must be printed with 2 decimal precision. You need to use f strings to achieve this. Using the round function will only leave you biting dust.
If you get style warnings about long lines, you can split a long string into multiple lines simply by partitioning it like this. The f prefix needs to be added to all parts that contain placeholders.
print(
“This do be a really really really long line of text ”
“and if you also want to add placeholders it’s gonna get even longer…”
)
Use Example:
Input distance traveled (m): 50.0
Input elapse time (s): 3.0
The speed of a car traveling 50.00 meters in 3.00 seconds is 60.00 km/h.
Input distance traveled (m): 50.0m
You need less donuts, and more number inputting.
Input distance traveled (m): 50.0
Input elapse time (s): minute
You need less donuts, and more number inputting.