Python Institute lab 3.1.2.15

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

intro to programming student i definitely can appreciate working the problem out during the video.

jimmymitchell
Автор

Where were you in 1997? If I had a professor that taught like this perhaps I would not have this stigma against programming. Great work, sir. Your videos are a huge help.

iyareomoruyi
Автор

Thanks you so much for the solution and all your videos you posted, i keep viewing them as i study.
So fucking noob even with solutions, still cant fully comprehend the entire logic enough to write it on my own.
Anyway... Just found a guys comment about this solution in which he proposes using while even at the first decision point BUT he takes first compare of c0 only as less than zero, and later. His solution prompts user to submit another input even when initially he enters a non-positive and non-zero number. Worth checking it out (different logic, in my point of view at least)

counter = 0
c0 = int(input("please enter a number: "))


while c0 <= 0:
print("please enter a positive number: ")
c0 = int(input("please enter a number: "))
else:
while c0 != 1:
if c0 % 2 == 0:
c0 = c0 // 2
print(c0)
elif c0 % 2 != 0:
c0 = 3 * c0 + 1
print(c0)
counter += 1
else:
print("steps =", counter)

ntripod
Автор

Got the same issue with else, fixed it by making it else()

continue and break works fine without it though.

hjanesh
Автор

at 8:41 correct me if I'm wrong but 2 goes into 7, 3 times not 6. 2X6=12.

poeticrecovery
Автор

Question. The version I tried was 2 If conditional statements for the even and odd calc within the loop with the same while c0 != 1 header. It did the calc correct but that never stopped running when calc got to 1. I tried adding a 3rd if statement if c0 ==1 then BREAK, didn't work. Same idea with ELSE statement, didn't work. I could not get the program to break. What is the lesson here since I would think the program would stop when calc gets to 1 either A. due to initial while statement != 1 or B. If (or else) statement if == 1 then break within the loop saying the same thing. Why couldn't the program see either of these the way I wrote it.?

jpljpl
Автор

nice tutorial video this is help me for my study

rafinurfadil
Автор

Thankyou soo much sir for making us understand this thing

gyanology
Автор

The problem is a practical one, so you can't increase the height to 1 before removing the first block.
So, the line with the removal of the blocks must come before the line with the height. So remove block No. 1, and the line becomes blocks = (block - 1) - height

This will give the correct answer without having to reverse the statements in an illogical manner.

mandrewlowe
Автор

I used natural numbers to represent the co, since natural numbers are numbers that are non-negative and non-zeros

alokamchinenyeaugusta
Автор

Is steps a keyword or function I didn't know about? I'm trying to do these now with your videos if i don't understand, but I hear what you say, then hypothesize what it will be and was not expecting that part. This is an amazing hypothesis by this guy though. Insane
Also, I was wondering what could be done to change the code to make that if statement at the top re-ask for a number if you put in a negative number. I made a loop but of course that infinitely tells me to enter another number.

captainvinno
Автор

To fix exit error:

Above line 1 (User input): add import sys then type sys.exit(0) for exit code

Should look something like this

import sys
c0=int(input("Enter a number: "))
if c0<1:
print("Error: Enter a number greater than 0")
sys.exit(0)

steven_narayan
Автор

Hi Ed,
First off thank you for taking the time to make these video's; you sure know how to explain this all in a comprehensive way! Just a question about entering -42 (at 17.30ish minutes): why not use exit() but use an else statement and indentations? Or is that just a personal preference?

Krausty
Автор

c0 = int(input("Enter a number: "))

step = 0

while c0 != 1:
if c0 % 2 == 0:
c0 = c0 / 2
step += 1
print(c0)
elif c0 % 2 != 0:
c0 = 3 * c0 + 1
step += 1
print(c0)
else:
break

print("Steps = " + str(step))

matthewemrys
Автор

using the int() function directly on the input causes an error if a non-integer is used, it somehow changes the value from a string to a number, but still treats it as a float and causes an error, e.g. I entered 6.6 and got: "ValueError: invalid literal for int() with base 10: '6.6'"

nickdownham
Автор

Can you help for Module 3: control statement. Complete Module 3 Lab Assessment coding activity
Module Lab Assessment 3: Abby's Ice Cream Shop

trambui