The following are some of the basic programs that I have learned from courses that I have taken, and books that I have purchased. I will be adding more demonstrations in the future. For the purpose of showing a basic understanding of Python, I chose some of the programs that touch on common topics such as loops and functions. I am using Visual Studio Code as my editor. I really enjoy the features that it includes.
A Few Basic Programs
The screenshot below is a basic number guessing game which imports the random library and sets a range of 1-10. The variables guess and tries are each set to the integer 0. The program will print the comment stating the purpose of the program. The program contains a while loop which will continue to work as long as the final condition has not been met. The final condition is that the number is guessed or the player runs out of tries. If the number is guessed, the program will print "You got it! Good guess!" If the number is not guessed, the program will print "You are out of guesses! Better luck next time!" As the player guesses the program will also give hints as to whether the guess was too high or too low. As you can see from the output I did not guess the secret number which was 10.
The following program is a simple temperature conversion program. In the output 0 degrees Celsius has been converted into 32 degrees Fahrenheit.
The program shown here is a basic function from Python Turtle which draws an eight sided figure then stops. The function move_and_turn uses the parameters distance and angle. Each time the function is called and an integer is assigned to the parameters, the curser, or turtle, will move and turn the distance and angle.
The following screenshot is the result of the program in the image above.
This program is also from Python Turtle. It works similar to the program above, but this one is using a for loop to draw the figure along with a function.
Here is the resulting shape from the program above.
This is a timer using a while loop that takes input from the user, and then counts down to zero in 1 second intervals. If the number is negative, the message states to enter a digit of 1 or higher. Once the countdown is complete, the program displays the "Time's up!" message.