본문 바로가기

Python9

Python_Day 9 Python Day 9_Beginner – Dictionaries, nesting and the secret auction Dictionaries To create a dictionary the syntax is {key: Value} which is the content. For example: {“Bug”: “An error in a program that prevents the program from running as expected.”} If you want to add more contents to the dictionary, you would add a comma at the end and continue. { “Bug”: “An error in a program that prevents t.. 2023. 12. 11.
Python_Day 8 Python day 8_Beginner Function parameters & Caesar Cipher Functions with input (review) # Review: # Create a function called greet(). # Write 3 print statements inside the function. # Call the greet() function and run your code. def greet(): print("Hello") print("This is a review for functions") print("Good Bye") greet() Adding variations in our functions (Can be modified) You can add input into.. 2023. 12. 7.
Python_Day 7 Python Day 7_Beginner – Hangman How to break a complex problem down into a flow chart (Flow chart programming) Challenge 1 – Picking a random word and checking import random #step 1 #TODO-2 - Ask the user to guess a letter and assign their answer to a variable called guess. Make guess lowercase. guess = input("Guess a letter: ").lower() #TODO-3 - Check if the letter the user guessed (guess) is o.. 2023. 12. 2.
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.