this is an c++ code , how can I implement this in python ?
while(scanf("%lld",&n)!=EOF)
{
cout<<convert(n)<<endl;
}
This is roughly equivalent:
def convert(input):
#do something with your input
import sys
for line in sys.stdin:
convert(int(line))
In Python, instead of using scanf
and friends, usually you read a line or an entire file into a string, and use string operations to get the results you want.
In your example, you could do something like:
import sys
for line in sys.stdin:
for word in line.split():
number = int(word)
... = convert(number)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.