
Python keeps giving me errors?


Line 7. can't convert string to integer. There is logic flow error too. As you should ask everytime inside loop
I managed to get rid of all those errors and now I got nothing outputting...
num_elements = float (input ("Enter a whole number: ")) #Question 1
for x in range (1, int (num_elements) + 1): #Question 2
if num_elements%3 == 0:
print ("Fizz") #Question 3 + 4
elif num_elements%5 == 0:
print ("Buzz") #Question 5
elif num_elements%3 == 0 and num_elements%5 == 0:
print ("FizzBuzz") #Question 6
ask_user = input (f"Exit the program? Y/N: ") # Question 9
if (ask_user. lower () == "y"):
print (f"Exiting the program...")
#elif:
#return num_elements
break
Enter a whole number: 1
Exit the program? Y/N: n
Process finished with exit code 0
I just added # to the Break and same thing. I've also tried to comment out the ask_user variable altogether and same result.
I just changed float to int... and same output that I sent you a minute ago
2 minutes ago*
Sorry about some of my code turning into sad emojis, that's the website/app, not what I originally wrote 🤦
Damn you're right, it works!
But now if I don't enter a valid number, if I type in n for the ask_user prompt, it keeps on looping
Oh shit, even if I type in y it's like that
Allowing Break to be code again makes the output end prematurely
Well the lab itself says to do a for loop which is dumb. But sure, I'll try doing a while loop then. It's super late for me, so I'll head to bed and continue this tomorrow. Thanks for helping me.
The other part of the lab I don't think I mentioned also requires me to add counter variables. I think I've done those before in Java, but not in Python. And I don't know how those would fit in a for loop. Thanks again.
X? What do you mean?
Pretty sure that only works for predetermined numbers and/or array shit I'd rather not code for this lab
num_fizz = "fizz"
num_buzz = "buzz"
num_fizz_buzz = "fizz_buzz" # Question 7
count1 = num_elements. count (num_fizz)
count2 = num_elements. count (num_buzz)
count3 = num_elements. count (num_fizz_buzz)
print ("The word "'"%s"'", appears %s times in the following text:\n%s\n" % #Question 8
(num_fizz, count1, num_elements))
print ("The word "'"%s"'", appears %s times in the following text:\n%s\n" %
(num_buzz, count2, num_elements))
print ("The word "'"%s"'", appears %s times in the following text:\n%s\n" %
(num_fizz_buzz, count3, num_elements))
Seems I can't get the counter variables to work properly either. I have to get the console to print out the number of times "fizz", "buzz", and "fizzbuzz" have been outputted based on num_elements.
Uh oh
I handed it in, but maybe I can submit it again before the deadline
Where would I add it exactly?
#Initialize with 0
count1=0
if num_elements%3 == 0:
print ("Fizz") #Question 3 + 4
count+=1 #this will increase count by one everytime fizz is printed.
#at end of code outside for loop
print (f"Fizz was printed {count1} times")
Not sure why a Y/N input is being converted to int.
That code has been made obsolete since a few hours ago
I can paste you the entire code if you want, but I may have to edit it so GaG won't glitch out and refuse to upload it as a reply.
So I apologize if the code looks disorderly if that happens
There is nothing disorderly in rhe process of learning. Good job and good luck.
Yeah but the code would be cause I'd have to squish everything together, or else GaG tells me unknown error. Fuck off stupid dumbass website
Opinion
0Opinion
Be the first girl to share an opinion
and earn 3 more Xper points!
You can also add your opinion below!