Complete beginner needs help - Python Help - Discussions on Python.org
Complete beginner needs help Python Help help Sybe (SybeTech) October 24, 2022, 12:43pm 1 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. Problem 634×888 138 KB abessman (Alexander Bessman) October 24, 2022, 1:41pm 2 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? vbrozik (Václav Brožík) October 24, 2022, 2:25pm 3 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 >>> aivarpaalberg (Aivar Paalberg) October 24, 2022, 2:33pm 4 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?
Sybe (SybeTech) October 24, 2022, 2:46pm 5 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. Sybe (SybeTech) October 24, 2022, 2:47pm 6 Thanks allot. I will give it a try in a different coding program. vbrozik (Václav Brožík) October 24, 2022, 2:54pm 7 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. Sybe (SybeTech) October 24, 2022, 3:40pm 8 It is working now!! Thanks allot. Sybe (SybeTech) October 27, 2022, 3:02pm 9 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. midlindner (Tod Lindner) October 27, 2022, 5:13pm 10 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? Sybe (SybeTech) October 28, 2022, 6:31am 11 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 print(max) This is the code I wrote. Not sure but looks correct to me. abdnafees (Abdullah Nafees) October 28, 2022, 6:56am 12 You will have to assign number to max not numbers . aivarpaalberg (Aivar Paalberg) October 28, 2022, 6:57am 13 Don’t use built-in names.
In this particular case max happens to have functionality what you have tried to code. Sybe (SybeTech) October 28, 2022, 7:09am 14 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 print(max) If I search for the smallest number in the numbers it works. I really dont get it. Sybe (SybeTech) October 28, 2022, 7:15am 15 yes youre right. Theres a mistake in it.
I will figure out. Because if I change 1 to 100 it gives the same error. abdnafees (Abdullah Nafees) October 28, 2022, 7:16am 16 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 print(maximum) Sybe (SybeTech) October 28, 2022, 7:41am 17 Thank you so much. It is all about the details… abdnafees (Abdullah Nafees) October 28, 2022, 7:42am 18 No problem.
Happy to help. midlindner (Tod Lindner) October 31, 2022, 8:01pm 19 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.
Sybe (SybeTech) November 2, 2022, 1:34pm 20 Thank you for this comment. These error messages are really helpfull.