The following questions were asked in the cram school assignments.
Create a list num from 1 to 30 using the comprehension and range. Create a list kisuu consisting of only odd numbers of 10 or less, with even numbers removed from the list num in a comprehension notation.
Then create an empty list guusuu.
Then declare the function tuika. Declare the variable abc with the argument a, add 1 to kisuu [a], make the odd number even, and return abc with return.
After that, declare a = 0, and while a is smaller than 7 in the while statement, put the one returned from the function tuika into the list of guusuu. However, when a becomes 5, the process is stopped with break.
Finally, display the lists kisuu and guusuu.
Where kisuu is displayed properly
guusuu remains empty.
What I tried
num = [x for x in range (1,31)] kisuu = [y for y in num if ((y<= 10) and (y% 2 == 1))] guusuu =  def tuika (a): abc = kisuu [a] +1 return abc a = 0 while a<7: guusuu = tuika () if a == 5: break print (kisuu) print (guusuu)
I wrote it in the order of the question sentences, but for some reason only the list of guusuu remains empty.
Is something wrong?
Answer # 1
Only pointed out because it is a problem
The block with a = 0 and while is indented too much and is included in the function definition, so it is not processed. Reduce your indentation by one.
As pointed out by many others, the increment process of a in while is missing.
-The process of adding the return value of the tuika function to the guusuu list is incorrect.
The call to the tuika function has no arguments. Maybe you should specify a.
The judgment of "when a becomes 5" is too late.
- i don't understand the exercises using python trigonometric functions
- i don't know the order of processing higher-order functions in python
- i don't understand the declaration part of the python code
- python - i want to prevent continuous execution of functions
- [python] i don't understand the meaning of the error
- i don't understand the behavior of the python for statement
- i want to create a function in python that all functions without class go through
- [python] i don't understand why the code can't be executed
- python - combine input with built-in functions
- python - i don't understand the indexing law of pandasseries i don't know how to take it out
- python - what i don't understand about yolo9000 (v2)
- python 3x - about functions used in python for statement
- i don't understand the meaning of x used in a python pandas lambda expression
- python - what you do not understand by calculating the precision and recall
- python - i can't understand the specifications of pandas
- python 3x - what is the best place to declare functions and classes in python?
- i want to limit the scope of python functions
- i don't understand the meaning of the python pandas code
- [python] functions in the class that inherits formatter do not work
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory