분류 전체보기160 Python_Day 6 Python Day 6_Functions and Karel Functions We can define our function with def -> def my_function(): with indentation def my_function(): print(“hello”) print(“bye”) my_function() -> it will run the defined function The hurdle loop challenge (https://reeborg.ca/) Indentation Only the indented codes in the function will be registered. Rest of the code outside the indentation will be considered ind.. 2023. 11. 30. Python_Day 5 Python Day 5_Python loops For loop for item in list_of_items: #do something to each item fruits = ["apple", "peach", "pear"] for fruit in fruits: print(fruit) Allows us to execute the same line of code multiple number of times. However if the print function or another code is out of the indentation loop then it won’t be part of the loop. We can add into the loop with print(fruit + “ pie”) which .. 2023. 11. 23. Python_Day 4 Python Day 4_Randomisation and Python Lists Randomization We use import random as a starting point. We can use randint(a, b) which will return a random integer between a and b (both inclusive). import random random_integer = random.randint(1, 10) print(random_integer) Module When the codes / scripts becomes too complicated or too long we can split them into different modules. This allows differe.. 2023. 11. 17. Python_Day 3 Python_Day 3 Conditional Statements, logical operators, code blocks and scope Conditional Statement Conditional statement is if/else. By using If it should be followed with a condition and if it doesn’t it should be changed to else. By using a bathtub as an example we can code as follows: water_level = 50 if water_level > 80: print(“Drain water”) else: print(“continue”) A code for a ticketing bo.. 2023. 11. 15. Python_Day 2 Primitive data types #string = string of characters and need to be created with “”. You can use [ ] to show the first character and use 0 such as print(“Hello”[0]) = H. Even numbers in “ “ will be counted as characters instead of number so print(“123” + “345”) = 12345 #Integer = Makes the code as numbers. With large numbers you can use _ instead of commas to make large numbers more easier to loo.. 2023. 11. 10. Python_Day 1 Printing, commenting, debugging, string Manipulation and variables Printing to the console We use the double quotation marks to indicate that anything in between those quotation marks are not code and just texts to print. These are called strings in programing. The double quotation marks shows the beginning and the end of the string of characters. Print(“Hello world!”) however if you don’t close.. 2023. 11. 10. 이전 1 ··· 6 7 8 9 10 11 12 ··· 27 다음