[英]Couldn't write the script in python for this program, Can someone please recommend anything to make it work
出于特定目的,想知道不可变列表中城市的温度。 他们有一定的标准来解决这个问题。 标准如下: SL NO Requirement Specification 1 提供一个选项,他们可以在华氏温度或摄氏温度范围内测量温度 2 输入您想要测量的温度值数量 3 将它们放入列表中或输入整个列表3 将温度从摄氏度转换为华氏度,反之亦然并打印出来
华氏度到摄氏度的转换公式如下: T(°C) = (T(°F) - 32) × 5/9 这里 T(°C) 是指摄氏温度,T(°F) 定义为华氏温度。 摄氏度到华氏度的换算公式如下: T(°F) = T(°C) × 9/5 + 32 这里 T(°C) 指摄氏温度,T(°F) 定义为华氏温度温度。 请为此编写一个 python 脚本。 请至少包含一个用户定义的 function。您可以使用 tuple() function 将列表转换为元组。
到目前为止,我的脚本如下;
n=int(input("Please enter the temperature observation"))
emptyList1=float[]
emptyList2 = float[]
C = float
F = float
for i in range (0,n):
t=(i+1 ," th Value")
emptyList1.append(t)
def C ():
C = (t-32)*(5/9)
def F ():
F = (t*(9/5)) + 32
print( "Enter C if the given temperature is in Fahrenheit and want to convert in Celcius, F if the temperature is in Celcius and want to convert in Farhenheit")
choice = input('Please enter your selected option: ')
if (choice==C):
C()
elif (choice==F):
F()
for t in range (emptyList1):
t1 = C(t)
emptyList2.append(t)
这有很多语法问题。
首先,不要将变量和方法命名为相同的东西。
其次,将类型分配给变量没有意义(例如C = float
)。
第三,您不应该首先拥有C
或F
变量 - 只需从您的方法返回一个值。
最后, if (choice == C)
应该是if (choice == 'C')
因为您想将输入与字符串'C'
进行比较,而不是名为C
的变量。
想知道特定目的不可变列表中城市的温度。 他们有一定的标准来解决这个问题。 标准如下: SL NO 要求 规范 1 提供一个选项,他们可以在华氏或摄氏温度范围内获取温度 2 输入您想要获取多少温度值 3 将它们放入列表中或输入整个列表3 将温度从摄氏温度转换为华氏温度,反之亦然并打印出来
华氏到摄氏的转换公式如下: T(°C) = (T(°F) - 32) × 5/9 这里 T(°C) 指的是摄氏温度,定义了 T(°F)对于华氏温度。 摄氏到华氏的转换公式如下: T(°F) = T(°C) × 9/5 + 32 这里 T(°C) 指的是摄氏温度,而 T(°F) 定义为华氏温度。 请为此编写 python 脚本。 请包含至少一个用户定义的 function。 您可以使用 tuple() function 将列表转换为元组。
到目前为止,我的脚本如下;
n=int(input("Please enter the temperature observation"))
emptyList1=float[]
emptyList2 = float[]
C = float
F = float
for i in range (0,n):
t=(i+1 ," th Value")
emptyList1.append(t)
def C ():
C = (t-32)*(5/9)
def F ():
F = (t*(9/5)) + 32
print( "Enter C if the given temperature is in Fahrenheit and want to convert in Celcius, F if the temperature is in Celcius and want to convert in Farhenheit")
choice = input('Please enter your selected option: ')
if (choice==C):
C()
elif (choice==F):
F()
for t in range (emptyList1):
t1 = C(t)
emptyList2.append(t)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.