Complete beginner needs help

Hello World (…;)))

I just started with Python. I am a absolute beginner. Started with the beginner tutorial of “Programming with Mosh”. Iam working on this car game with a while loop. Somehow the coding doesnt seems to be correct. When I enter the input words nothing happens.

Maybe one of you can see my fault.

Code looks OK. But please don’t post screenshots of code, paste the actual code within triple backticks:

Your code goes here.

Looks like you’re using VScode. I don’t use it for Python development personally, but could it be that the output gets printed in the OUTPUT tab in the bottom pane?

Which shell are you running inside the terminal? You are using it as PowerShell but the prompt does not look like the default PowerShell prompt. On my Windows 10 it looks like below - followed by showing the PowerShell version.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell

PS C:\Users\vaclav.brozik>
PS C:\Users\vaclav.brozik> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1682
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1682
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3

…also your Python installation location is weird. By default it is in C:\Program Files\ on Windows. I have python.exe in my path:

PS C:\Users\vaclav.brozik> Get-Command python | Format-Table -AutoSize

CommandType Name       Version        Source
----------- ----       -------        ------
Application python.exe 3.10.1150.1013 C:\Program Files\Python310\python.exe

Running Python in interactive mode from PoweShell:

PS C:\Users\vaclav.brozik> python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 2

Some observations about code:

  • until ‘quit’ is entered it will be looping indefinitely i.e. if ‘start’ is entered, it prints ‘Car starts’ and prompts for the next entry with the next iteration of the loop
  • when ‘quit’ entered it will print out “Sorry we don’t understand” before stopping the loop

Are these behaviors desirable or not?

1 Like

I think I need to change program. I had some issues before with VScode and stuff that didnt worked out. I will de-install VScode. And will install a different code program and try again. Thx for youre help!!

Next time I will enter my code. :slight_smile:

Thanks allot. I will give it a try in a different coding program.

The problem is not in VS Code. First try to run Python in interactive mode in a terminal on your computer - as I have shown above. :slight_smile:

It is working now!! Thanks allot.

I upgraded a old computer from windows 7 to windows 10.
Now I can work on a big screen.
Had to reinstall python again. Using it again in Visual Studio Code.
A new problem occured.

When I enter arithmetic operations like: += or > I am getting this message:

File “c:\Users\Gebruiker\4. Opdracht”, line 6, in
if number > max:
TypeError: ‘>’ not supported between instances of ‘int’ and ‘list’

Do I need to install some package to let these operations work?
Already did some research on the web but couldnt find a solution.

The error is telling you that your variable, max is assigned to a list. How would you compare an int to a list, and determine whether the int is greater than the list?

Perhaps you meant to compare the int with an individual element of the list?

1 Like
numbers = [1,4,6,7,12,565,21,346,234,5,24,12,1223]
max = numbers [0]
for number in numbers:
    if number > max:
        max = numbers

This is the code I wrote. Not sure but looks correct to me.

You will have to assign number to max not numbers.

Don’t use built-in names. In this particular case max happens to have functionality what you have tried to code.

numbers = [1,4,6,7,12,565,21,346,234,5,24,12,1223]
max = numbers [0]
for number in numbers:
    if number < max:
        max = numbers

If I search for the smallest number in the numbers it works. I really dont get it.

yes youre right.
Theres a mistake in it. I will figure out.
Because if I change 1 to 100 it gives the same error.

Try this:

numbers = [1,4,6,7,12,565,21,346,234,5,24,12,1223]
maximum = 0
for number in numbers:
    if number > maximum:
        maximum = number

Thank you so much. It is all about the details…:wink:

1 Like

No problem. Happy to help.

1 Like

I see that you’ve found a working solution, but I’m not sure if you realize what the original problem was.
Looking at your code, and the error message you originally posted,


numbers = [1,4,6,7,12,565,21,346,234,5,24,12,1223]
max = numbers [0]
for number in numbers:
    if number > max:
        max = numbers #what is this line doing?

The first iteration of the for loop works fine. Your if statement compares the first element of numbers which is 1 with the value max is assigned to which is numbers[0] also 1. Then you assign max to numbers. What is numbers? It’s the entire list. On the second iteration of your for loop, the error is thrown when you try to compare the 2nd element of numbers with max which is now assigned to the list, numbers.

Reading and understanding the error messages provided by Python, and using the information provided to debug your code is an extremely valuable skill to develop.

Thank you for this comment. These error messages are really helpfull.

1 Like