Intro to Python Programming
Hi! Today I’m posting about the first class I had in the intro to Python programming that ocurred yesterday.
The teacher is an applied mathematician, Prof. Dimas, and he works with the Algorithms and Data Structures (ADS) part of the applied math, I had the class ADS while i was an undergraduate with a teacher from the Computer Science Dept. but I never really learned how to code, just the definitions and the behaviour of some commands, but not the creative and beautifull part of programming.
So the teacher decide to make the course in a motivational way, instead of following some book and learning the basics in some rigid order we are going to be presented to problems and try to make a functioning code at the end of every class. Clearly every class is going to be fun and interesting.
The first problem is the “Guess the number” game. The teacher guided us creating a code for a game wich determines a certain random number between 1 and 100, and then asks the user for a guess, giving feedback on wether he is right or wrong, and if he guessed too high or too low, also there is the option to quit the game.
By the end of the class my code was like this.
-----------------------------------------------------------------------------------------------------------
y = random.randint(1,100)
print("What is the number that i thought")
x = input("Number value")
while True:
if x == 'Q':
break
x = int(x)
if x == y:
print('Congratulations, you are right!')
break
elif x > y:
print('Too big')
else:
print(' Too smal')
print('Try again. To quit press Q')
x = int(input())
-----------------------------------------------------------------------------------------------------------
I know it’s can be reduced and I probably put some redundant line somewhere, but I will keep improving the codes as the classes keep progressing.