Python Forum
Need assistance with this code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need assistance with this code
#1
Hello Gurus,

I need some help with creating a program for a parrot. Here is the information below.

1. Create a program that is a parrot. The program should begin by printing "Polly wants a cracker" on the screen. Then wait for the user to enter something (text). The program should then repeat whatever was entered back on the screen, followed by "Now give me a cracker.". Here is an example:

Polly wants a cracker.
>> Polly is nice.
Polly is nice. Now give me a cracker.


This is my program but I need some help with this code. I'm not sure how to complete this code. I'm not sure how to let the user enter text and what exactly are they entering. Lastly, I am not sure how to create the last two sentence.

parrot = "polly wants a cracker"
print(parrot)
polly= "polly is nice"
print(polly)

Thanks in advance for your help in this matter.
aka2d7
Reply
#2
Try this:

# Print initial request for a cracker
print("Poly wants a cracker.")
# We will repeat further code forever
while True:
    # Save keyboard input to the variable "input_value"
    input_value = input()
    # Print keyboard input and "Now give me a cracker"
    print(input_value + " Now give me a cracker.")
    # Repeat
Lines starting with "#" are just comments with explanations.
Reply
#3
Hi Tim,

I really appreciate your help but I need a little more details to help me understand this code. when I run this the "Now give me a cracker doesn't print. also can you please explain how does it know to print the Polly is nice. What happens there? I truly appreciate your quick response.

Thanks,
aka2d7
Reply
#4
Well, the program do exactly what you want from it:

1) Prints "Poly wants a cracker." with command print("Poly wants a cracker.")
2) Waits for your input - you can type whatever you want. The input will be saved to variable input_value. You must hit "enter" after you'll finish with your input.
3) When you hit enter, your input will be printed on output and the " Now give me a cracker." string will be put after it.
4) Program again waits for your input - this is repeating forever because of the while True: loop.
Reply
#5
Hi Tim,

Your AWESOME! Thank you so much!! This what I needed to understand your code and I appreciate your help in this example. I need help with a few more things do I post each thing that I need help with.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code Assistance needed in saving the file MithunT 0 830 Oct-09-2022, 03:50 PM
Last Post: MithunT
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,296 Feb-24-2021, 10:43 PM
Last Post: nilamo
  Python Code Assistance bfpa40 2 2,393 Oct-24-2018, 01:40 AM
Last Post: bfpa40
  i need assistance on the output of a particular code sirvinprogramming 3 3,345 May-19-2018, 03:37 PM
Last Post: buran
  Assistance Modifying Code chuco61 2 3,500 Apr-30-2017, 03:35 PM
Last Post: michaelcollier

Forum Jump:

User Panel Messages

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