Scroll to see replies
•
Firstly, you cannot put a function inside of a function. A function is a piece of code that is designed to do a certain task, so naturally putting one inside of the other doesn't really make much sense.
•
A lot of your indentation is also wrong. When creating a loop, you cannot just type "while True:" as this will create an infinite loop (you never want these). I would recommend using functions instead of loops to do things such as enter survival rates, but that's just personal opinion. If you do want to use loops, follow this syntax (scroll down to the first example).
•
On your menu, you cannot just type "print("1: Set generation 0 values")" and assume that Python will know that the user is meant to enter. Instead, you should let Python know that the user is meant to enter something here. This can be done by typing "variableName = input("Text here").
while True: if some_condition: break
global (variablename)
(without the brackets, just fill change variablename to whatever your variable is called) on the very top line of your code. Then when you want to use this variable later on, just typeglobal (variablename)
on the line above where you want to use your variable.def menu():
menuOption = int(input("Please enter your option: "))
def anotherFunction():
if menuOption = "1":
pass
else:
pass
This would not work as we have not globalised our variable menuOption.global menuOption
def menuOption():
global menuOption
menuOption = int(input("Please enter your option: "))
def anotherFunction():
global menuOption
if menuOption = "1":
pass
else:
pass
This should work Last reply 17 hours ago
Is MathsFM French Alevels good for a CS degree at top uni (OX, UCL, Durham etc)Last reply 2 days ago
OCR A-level Computer Science Paper 1 (H446/01) - 12th June 2023 [Exam Chat]Last reply 2 weeks ago
OCR A-level Computer Science Paper 2 (H446/02) - 19th June 2023 [Exam Chat]Last reply 3 weeks ago
AQA A-level Computer Science Paper 1 (7517 1A - 1E) - 12th June 2023 [Exam Chat]Last reply 4 weeks ago
Not receiving any response from University of Birmingham.Last reply 3 months ago
OCR GCSE Computer Science Paper 1 (J277/01) - 19th May 2023 [Exam Chat]Last reply 3 months ago
AQA GCSE Computer Science Paper 2 (8525/2) - 25th May 2023 [Exam Chat]Last reply 17 hours ago
Is MathsFM French Alevels good for a CS degree at top uni (OX, UCL, Durham etc)Last reply 2 days ago
OCR A-level Computer Science Paper 1 (H446/01) - 12th June 2023 [Exam Chat]Last reply 2 weeks ago
OCR A-level Computer Science Paper 2 (H446/02) - 19th June 2023 [Exam Chat]Last reply 3 weeks ago
AQA A-level Computer Science Paper 1 (7517 1A - 1E) - 12th June 2023 [Exam Chat]Last reply 4 weeks ago
Not receiving any response from University of Birmingham.Last reply 3 months ago
OCR GCSE Computer Science Paper 1 (J277/01) - 19th May 2023 [Exam Chat]Last reply 3 months ago
AQA GCSE Computer Science Paper 2 (8525/2) - 25th May 2023 [Exam Chat]