Can someone review problem 0 that I completed for the course? Here is my code: question1 = "What is your date of birth?" print question1 answer1 = raw_input() question2 = "What is your last name?" print question2 answer2 = raw_input() print ("Your date of birth is " + answer1 + " and your last name is " + answer2)
Can you give a bit more details what the problem is? What language this solution is in?
@test_user They are in the MIT 6.00 thing. That is a Python based class. @Elvera49 That is kind of overkill. You are using a varible to store text that could just as easily live in the print on the next line. ``` question1 = "What is your date of birth?" print question1 answer1 = raw_input() question2 = "What is your last name?" print question2 answer2 = raw_input() print ("Your date of birth is " + answer1 + " and your last name is " + answer2) ``` becomes: ``` print ("What is your date of birth?") answer1 = raw_input() print ("What is your last name?") answer2 = raw_input() print ("Your date of birth is " + answer1 + " and your last name is " + answer2) ``` Oh, and I put \(\text{```}\) (the one on the key with ~) above and below the code block to do the highlighting, and help formatting.
raw_input() will display a prompt, and return what the user types in (as a string). You could just put: answer1 = raw_input( "What is your date of birth? " ) BTW, raw_input() is one of the functions that is different between Python 2 and Python 3.
True, it can collapse even more, making it cleaner still.
Yes, but I won't recommend doing that for someone doing PS0.
Great, thanks for the replies. Sorry - i didn't realize that my question wasn't placed into the MIT 6.00 Intro Computer Science thread. Next time I will be more clear. I didn't realize that you could combine everything like that. That does save time. @e.mccormick what do you mean that you added the ``` above and below the code? I do not see it there?
@e.mccormick is right on the money in my book.....
but I have a question for you @Elvera49....why did you choose to define question 1 and question 2? I'm just trying to probe you with a question so you can associate with the logic more....the raw input function is going to make you or the user input the answer....then the print function will show how its displayed....have you done the credit card question in problem set 1? I'm stuck on the range and count part of the query….let me know…i'd love to collaborate on these courses…..
@Elvera49 You are in the correct section. test_user, who is an alt of one of the site coders, did not realize it. The \(\text{```}\) does not show up because it gets translated into formatting. For inline, one does it. `print("bla")`. See the box? I typed \(\text{`print("bla")`}\) and i am using the \(\LaTeX\) system to override it. It does syntax highlighting to some extent too. ``` for i in range(10) print i critters = ["owl", "python", "dog"] for c in critters: print (c, len(c)) ``` See the different colors and the box? That is the \(\text{```}\) system at work.
@roderick_camarce You can open a question on that. Put in your code. Get some help. Or put in the code that confuses you.
Join our real-time social learning platform and learn together with your friends!