Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Headfirst Python Exercise
#1
Hi guys, I have a question. I'm currently working my way through the Headfirst Python book. And there is an exercise where you create an app based around the song 99 bottles of beer. I'll paste the code here in a moment.
word = "bottles"

for beer_num in range(99, 0, -1):


    print(beer_num, word, "of beer on the wall.")

    print(beer_num, word, "of beer.")

    print("Take one down.")

    print("Pass it around.")

    if beer_num ==1:

        print("No more bottles of beer on the wall.")

    else:

        new_num = beer_num - 1

        if new_num == 1:

            word = "bottle"

        print(new_num, word, "of beer on the wall.")


    print()
My question is regarding beer_num, is this what you write when you want Python to determine how many times a word appears?

I just deleted beer and replaced it with a different word, and it works in the same way

So I guess that it is
Yoriz write Jun-05-2022, 10:50 AM:
Please post all code, output and errors (In their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Headfirst Python Exercise - by GeorgeSears - Jun-05-2022, 10:27 AM
RE: Headfirst Python Exercise - by menator01 - Jun-05-2022, 11:52 AM
RE: Headfirst Python Exercise - by jefsummers - Jun-05-2022, 12:07 PM
RE: Headfirst Python Exercise - by GeorgeSears - Jun-11-2022, 06:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Wrong code in Python exercise MaartenRo 2 1,564 Jan-01-2022, 04:12 PM
Last Post: MaartenRo
  Python Exercise Doubt azure 4 2,725 Apr-21-2020, 01:15 PM
Last Post: azure
  New to python, having trouble with an exercise Salkay 3 2,209 Feb-18-2020, 01:42 AM
Last Post: Salkay
  Exercise 20, Learn Python 3 the Hard Way Dixon 6 6,096 Feb-26-2018, 04:54 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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