Ask Your Question
0

what is the equivalent of cin>> in sage

asked 2016-08-31 22:08:43 +0100

nebuckandazzer gravatar image

updated 2016-08-31 22:09:08 +0100

I am familiar with C++. In C++, the syntax to give input is cin>>. What is the equivalent of cin>> in sage ? I am declaring an integer $n$ (in C++ syntax we write int n) and the user will give the value of $n$ when the program is being run.

How do I do that ?

It would be really helpful if you can give an example. (Say, the purpose of the program is to print an integer given by the user. What will be the syntax ?)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-08-31 22:16:50 +0100

kcrisman gravatar image

I guess you could use raw_input()/input() (depending on Py2 versus Py3). If I understand your question correctly?

BUT you will have to be careful, because the raw input won't be preparsed (although you can ask for it to do that too, I guess). E.g. a file test.sage like this is bad:

a = raw_input()
print a^2

while

a = raw_input()
print Integer(a)^2

does more what one would expect.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-08-31 22:08:43 +0100

Seen: 321 times

Last updated: Aug 31 '16