Ask Your Question

what is the equivalent of cin>> in sage

asked 2016-08-31 15:08:43 -0500

nebuckandazzer gravatar image

updated 2016-08-31 15:09:08 -0500

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

answered 2016-08-31 15:16:50 -0500

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


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


Asked: 2016-08-31 15:08:43 -0500

Seen: 34 times

Last updated: Aug 31 '16