I just finished my attempt on set 0 my only issue is how do i force the person to put in the date like 12/12/12 instead of spelling out the month
What the sweet and salted chocolate wafers are you going on about?
You have to do input verification. At the earliest steages of learning, you assume people will do what you want. Only after you get past the basics do you begin to worry about these practical matters.
The best you can do at this point is suggest the format in your prompt: foo = raw_input( "Please enter a date mm/dd/yy: " )
Hi Ricardopl, I haven't ever programmed before but I used some of the stuff he discussed in the lectures. If length does not equal dd/mm/yyyy (10 char), ask again, otherwise exit loop. it doesn't validate for anything besides length but it was my stab at answering the exact same question. while True: x = raw_input('What is your date of birth? (enter mm/dd/yyyy)\n') if len(x) != 10: print("Please enter mm/dd/yyyy format") else: break y = raw_input('What is your last name?\n') print y + ' ' + x
well I used the following code to make them enter it that way : bdate = raw_input("Enter your birthday in the format mm/dd/yyyy")
Hi Ricardo! It all depends on how you write out your code. I recommend Ex12 on Learn Python the Hard Way, 3rd Edition. Here is the url: http://learnpythonthehardway.org/book/ex12.html
I am probably way too late on answering this one, but I struggled through this first problem set as well. The Python books I had on-hand didn't do a great job explaining the basic loop info and a lot of the stuff that seemed like it should have worked, errored out. I have very little programming experience so this could be wrong. However, both produced what appears to be a correct final output. Here is what I came up with: The first solution I created was a basic straight line program that didn't loop back in the event of an incorrect dob entry: y = int (raw_input('Please enter your date of birth (mmddyyyy): ')) x = raw_input('Please enter your last name: ') print x, y The second solution I came up with codes a loop into the program which accounts for users entering less than the requested 10 digit dob. y = raw_input('Please enter your date of birth (mm/dd/yyyy): ') if len(y) != 10: y = raw_input('Please enter your date of birth (mm/dd/yyyy): ') if len(y) == 10: x = raw_input('Please enter your last name: ') print x, y Happy coding :)
That's not really a loop. To do that verification with a loop would be more: y = "" while( len( y ) != 10 ): y = raw_input('Please enter your date of birth (mm/dd/yyyy): ') x = raw_input('Please enter your last name: ') print x,y Try entering the date wrong with your code 3 times and see what you get, then copy in my changes and try it however many times you want. You can fail mine forever, you're not going to go anywhere.
Thanks for responding rsmith -- you're right it's not really a loop. I figured that out after I posted this. I appreciate you taking the time to respond with code. I am going to try this out tomorrow during study time.
Join our real-time social learning platform and learn together with your friends!