387
Pe
python-exercices / files
python-exercices / level_two / ex_6.py
1.1 KB
1#!/usr/bin/env python3 2 3# Question 6 4# Level 2 5 6# Question: 7# Write a program that calculates and prints the value according to the given 8# formula: 9# Q = Square root of [(2 * C * D)/H] 10# Following are the fixed values of C and H: 11# C is 50. H is 30. D is the variable whose values should be input to your 12# program in a comma-separated sequence. 13# Example 14# Let us assume the following comma separated input sequence is given to the 15# program: 16# 100,150,180 17# The output of the program should be: 18# 18,22,24 19 20# Hints: 21# If the output received is in decimal form, it should be rounded off to its 22# nearest value (for example, if the output received is 26.0, it should be 23# printed as 26) 24# In case of input data being supplied to the question, it should be assumed to 25# be a console input. 26import math 27 28C = 50 29H = 30 30input_sequence = input('\n\nEnter a comma-separated sequence\n') 31 32 33def Q(D): 34 return round(math.sqrt((2 * C * D) / H)) 35 36 37results = [] 38input_list = [int(i) for i in input_sequence.split(',')] 39for number in input_list: 40 results.append(Q(number)) 41 42print(results)