Übung2
Compare changes
- mariah15 authored
oop-Ubungen.py deleted
100644 → 0
+ 0
− 111
This function creates an infinite loop using a while statement with the condition True, and prints a message to the console each time the loop executes.
While this algorithm is not useful in most situations, it can be used as a placeholder or a stand-in for more complex code that hasn't been written yet.
For example, you might use an infinite loop like this in a program that you're developing iteratively, where you want to test how the program behaves in the absence of some functionality that you haven't implemented yet.
However, it's important to be careful when using infinite loops like this, since they can easily cause your program to become unresponsive or crash if left running for too long.
It's a good practice to always have some way to break out of an infinite loop, such as a user input or a condition that becomes true after a certain amount of time has elapsed.
This function takes a list as input, and returns a random item from the list, or None if the list is empty.
The randomness comes from the use of the random.randint function, which generates a random integer between the two provided arguments.
However, the determinism of this function is not clear. While the use of random.randint suggests that the function is non-deterministic,
it's possible that the same result could be produced repeatedly if the function is called with the same input list multiple times.
For example, if get_random_item is called with the same list twice in a row, it's possible that it could return the same random item both times.
but the deterministic behavior would be a side effect of the input rather than an intrinsic property of the function itself.
This function takes a positive integer n as input and outputs the numbers from 1 to n to the console using the print function.
However, it doesn't return anything explicitly, so if you were to call it and try to assign its output to a variable or use it in another part of your program,
Again, this is not necessarily a bad thing, as sometimes you might want a function to perform a side effect like printing to the console without returning any output.
However, if you need the output of a function for use elsewhere in your program, make sure it actually returns something!
# While the water is heating up, take an egg from the refrigerator and let it come to room temperature.
# After 12 minutes, turn off the heat and carefully remove the egg from the pot using a slotted spoon.