译者应用程序故障?我的for循环运行错误,但为什么呢? [英] Translator app malfunction? My for loop is running a error, but why?

查看:86
本文介绍了译者应用程序故障?我的for循环运行错误,但为什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在python中创建一个你输入数字的程序,我的系统会将你输入的数字(Cal)转换成输出数字(Kel)。每5卡,一卡。但是我的系统一直运行错误?为什么?

So i am making a program in python where you type in a number, and my system translates the number you typed, (Cal) to the output number (Kel). For every 5 cal, its one kel. However my system keeps running a error? Why?

CtoM = int(input("List a number to translate  Cal to Kel !"))
num = 0
for 5 in CtoM:
    num+=1
print(CtoM)





我尝试了什么:



我试图谷歌应该如何使用for循环的例子,因为也许我的for循环是错误。所以经过一段时间的谷歌我被带到这个页面: Python for Loops [ ^ ]

阅读完文章后我非常肯定我写的代码正确。从网站上看这个例子:



What I have tried:

I tried to google examples of how for loops should be used, because maybe my for loop is the error. So after a while of google i was brought to this page: Python For Loops[^]
after reading the article i was pretty sure i wrote the code correctly. Look at this example from the site:

fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)



这就是我在做什么,但是我使用的是数字而不是X.

我很困惑,任何人都可以请help?


This is what i am doing, but i used a number and not X.
Im so confused, can anyone please help?

推荐答案

for 5 in CtoM:



你不能拥有一个名为'5'的变量,因为这是一个恒定的值。我建议你去 Python教程 - Python 3.4.9文档 [ ^ ]并完成了几次。


You cannot have a variable called '5', since that is a constant value. I suggest you go to The Python Tutorial — Python 3.4.9 documentation[^] and work through it a couple of times.


您不需要转换循环(分区就足够了)。此外,您的代码基于完全偏离主题的示例代码。
You don't need a loop for the conversion (a division is just enough). Moreover you based your code on a completely off-topic sample code.


这篇关于译者应用程序故障?我的for循环运行错误,但为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆