Python Forum
I'm not sure what I'm doing wrong here...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm not sure what I'm doing wrong here...
#1
Hey all, beginning programmer here.

I've been working on a very simple Mad Libs-style "game" in python 2.7 and I've run into some trouble when trying to execute it. 


The program has five variables: a number (number1), a verb (verb1), a color (color1), a noun (noun1), and a name (name1). The program asks you to fill them in, in that order, and they appear in the following generated story in that order (or at least they're supposed to).

Here is the empty sentence without any of the variables filled in: "I saw <number1> <color> <verb1> <noun1> the other day. It said to me, 'Hi, my name is <name1>.'"
Here is the sentence with the variables filled in as an example: "I saw one green hopping bird the other day. It said to me, 'Hi, my name is Frank.'"

Seems simple right? Well it gets a little more complicated.

Basically the program accounts for a value greater than 1 being assigned to number1. The reason why this is important is because if number1 > 1 but noun1 <= 1, the sentence becomes grammatically incorrect. "I saw ten green hopping bird the other day. It said to me, 'Hi, my name is Frank.'" Hopefully you see what I mean. It's also worth mentioning that the sentence changes from "It said to me" to "The first one said to me" if number1 > 1.

Therefore I (tried) implementing a system in which the program checks whether or not number1 is plural, and if it is, it changes the raw_input of noun1, as you can see on line 17. The "default" raw_input command for noun1 would be raw_input("Choose a noun.") However if the program detects number1 > 1, it changes to raw_input("Choose a plural noun.") and if number1 <= 1 it becomes raw_input("Choose a singular noun."). So long as the user follows the instructions the sentence should be grammatically correct and thus flexible to both plural and singular subjects. 

I also have a final_product variable that is the sentence, and I'm using %s to fill in the blanks with the player input as you can see on line 30. 

Hopefully all of this makes sense.

So here's the problem: when I execute the code, wherein
number1 = one
verb1 = hopping
color1 = green
noun1 = bird
name1 = Frank

I get this:
"I saw <function number1 at 0x03039930> hopping green <function noun1 at 0x03039970> the other day. The first one said to me, 'Hi, my name is Frank.'"

There's not even any error messages or anything, it's just that for some reason he values for number1 and noun1 aren't filled in. Furthermore the program didn't ask me for a noun (singular or plural), it just skipped over to name. And the sentence doesn't change from "The first one said" to "It said" based on the number1 input.

I have no clue how I'm supposed to solve this. I hope some more experienced folk can help me out and I'd be very grateful for it.
Reply


Messages In This Thread
I'm not sure what I'm doing wrong here... - by Fazz - Nov-01-2016, 01:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,885 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 3,133 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020