type conversion and variable calculation python

https://blog.csdn.net/weixin_43379056/article/details/86717780

Q
write a program, to be able to enter a number, and then complete q = [(2 * c * d) / h], where
C = 50
H = 30
D are input variables
, for example, is input 100,150,180
output on It should be 18,22,24

This is my first complete a separate code, I feel nothing when you see the difficulty of the question,
because in a tuple I've learned how conversion type, yet again and again hit the real face
first problem I encountered is input the content can only be converted into a tuple, do not know how to
translate directly into the list, so the secondary reformer for a moment, and then is found after printing results with []
so they look only to find that the value of one by one so as to output the list

Knowledge
math module - math modules, including a lot of ways
sqrt method - that is, the square root of 2

"" "
Introduction mathematical module
2 introduced conversion module
3 receives user input and conversion of
4 loops through the mathematical model, math.sqrt method prescribing
5 print result
" ""

import math
import ast
c = 50
h = 30

= value []
VALUE_LIST = ast.literal_eval (INPUT ( "Please enter a number to be calculated, and separated by commas:"))
VALUE_LIST = List (VALUE_LIST)

for i in value_list:
n = math.sqrt((2 * c * i) / h)
value.append(int(n))

print(*value, sep=",")

Released eight original articles · won praise 0 · Views 1357

Guess you like

Origin blog.csdn.net/qy00131717/article/details/104329828