Python - Week 3 - Lists, Tuples, Slicing, Math Functions
This week I tried another problem from github:
Write a program that calculates and prints the value according to the given formula:
Q = Square root of [(2 * C * D)/H]
Following are the fixed values of C and H:
C is 50. H is 30.
D is the variable whose values should be input to your program in a comma-separated sequence.
Example
Let us assume the following comma separated input sequence is given to the program:
100,150,180
The output of the program should be:
18,22,24
Some interesting findings from this program:Write a program that calculates and prints the value according to the given formula:
Q = Square root of [(2 * C * D)/H]
Following are the fixed values of C and H:
C is 50. H is 30.
D is the variable whose values should be input to your program in a comma-separated sequence.
Example
Let us assume the following comma separated input sequence is given to the program:
100,150,180
The output of the program should be:
18,22,24
- The import in Python is done using 'from ... import ..' statement. This is used in our program to use round and sqrt functions.
- Tuple is an immutable sequence type. Functionally, they’re used to represent fixed collections of items.
- print function takes an argument which by default is '\n'. In our case, we are using a different end character ','
- Slicing is a way to extract an entire section (slice) in a single step.
- printSeries[0:-1] - is used here to slice the list starting from index 0 until one but last item. printSeries[-1] is the last item in list.
Comments
Post a Comment