Python Forum
beginner and need help with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
beginner and need help with python
#1
Hi i just wanted some advice and some help with python

i am learning python and i have no confidence of solving a little problem or even writing a little LINE of code so far we did with while loops as practise i didn't even know where to start to be honest and wanted what to do even learn how to code from the basic i would say and if anyone want to help me i would be glad to contact you though email or here thanks.

this is the practise question i had for while loops:

"Write the beer program again, counting down from 10 to 0 bottles, but for the special case of 6 bottles of beer, printing six pack instead.

Use different looping methods:

1. a while loop
2. a for loop with the appropriate range function

next topic we have is lists and i been watching some youtube "python beginners" and couldn't even solve the practise questions i had from my professor.
Reply
#2
hello
probably you didnt understand the while & For & range and if statement well
as there are a lot of tutorials online, when you dont understand something on a channel just write the function name on youtube and look at it in another channel,
basics are the base structure to move on, so take your time learning them.
be patient dont worry it happens to everyone
Reply
#3
Maybe this will help.

while-loop (while loop executes until condition becomes False)

n = 5                  # initial value

while 0 <= n:          # while value is greater or even 0
    print(n)           # print value
    n -= 1             # decrease value by one, go back to row #3 (loop)
Output:
5 4 3 2 1 0
for-loop (for loop executes until exhausted):

for i in range(5, -1, -1):      # range from 5 to -1 (excluded) incremented by -1 on every step
    print(i)
Output:
5 4 3 2 1 0
Python interactive interpreter has built-in help. At first it may seem too intimidating but if you really want to learn programming you should get acquainted with terminology and style of help. Just type >>> help('for'), >>> help('while'), >>> help(range) (press Q to exit the help)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
(Oct-13-2019, 07:35 PM)Tjay Wrote: Write the beer program again, counting down from 10 to 0 bottles, but for the special case of 6 bottles of beer, printing six pack instead

Supposedly you already have some code for this program and you are expected to produce different output for a particular case (i.e. number of bottles). Please, post the code you have so far in python tags, full traceback if you have any exceptions - in error tags.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Hi thanks for the replies, i really appreciate it.

Quote:i= 1
while i<=5:
print("beer")
else i=6
print("sixpack")
else i=10
print("beer")

this what i initially came up with using some logic and trying solve it like a math problem while wording using english but not the computer terminology and thats what i came up with and know its wrong even though i have the solution for it but i would like to go through my code above and get it correct and understand it.

thanks.

Also i am doing list on the side aswell trying get ahead before my next class

This is the question:

Create a simple list to hold the items 1,2,3,4, creating the list “from the front” as in Slide 48.[Notice how the list is only complete when you have finished.]Use the code from Slide 50 to print out your list. (You may want to write this as a function.)

Quote:class Node:
pass

start = Node()
point = start

point.data = 1
point.next = Node()
point = point.next

point.data = 2
point.next = Node()
point = point.next

point.data = 3
point.next = Node()
point = point.next

point.data = 4
point.next = None

def func1():
point = start
print(point.data)

point = point.next
print(point.data)

point = point.next

print(point.data)
point = point.next
print(point.data)
point = point.next
print("point:", point)

func1()

And just wanted did i assemble the code properly that i got from the slide 48 and 50(read question)
Reply
#6
Rather than using quotes, you want to use Python tags (the yellow and blue icon beside quote)
i= 1
while i<=5:
    print("beer")
else i=6
    print("sixpack")
else i=10
    print("beer")
Else is usually used with if, and yes you will need to use if. Take your while and make is <=10, then first line after that make an if statement that tests to see if i is 6. If so, print sixpack, else print beer.
AND, you never increment i so it will always be 1, and you will get endless beer (not an entirely bad outcome).
Reply
#7
Thanks for your reply and this what i came up with after trying to improve and i didn't understand what you meant by "Take your while and make is <=10" bit

i = 10

while i > 0:
  if i == 6:
    print("sixpack")

  else i == 1:
    print("beer")

  else i < 1 

print ("no beer")
Reply
#8
Why are you checking if i == 1?
In that first else, wouldn't you get what you want if you just had else:
and do you need that last else clause?
And, you still aren't changing the value of i so, endless beer! You're a distillery!
jk
Reply
#9
okay, i have removed the "i==1" and also i thought i stopped the endless beer using the last else clause Think Big Grin

i = 10


while i > 0:
  if i == 6:
    print("sixpack")

  else 
    print("beer")

  else i < 1 

print ("no beer")
Reply
#10
(Oct-14-2019, 07:23 PM)Tjay Wrote: i thought i stopped the endless beer using the last else clause
and how you decide that when your code cannot run because of errors?
what do you think line 11 is supposed to do? do you think you made i change its value in the loop body?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

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