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.
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 https://aka.ms/pscore6
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
SerializationVersion 1.1.0.1
…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
3
>>>
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
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!!
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 Lists.py”, 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?
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,
Consider:
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?
print(max)
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.