Fundamentals in Python

 

Flowchart




Working with Spyder was a challenge. I had started on step 1 on a different approach than the lab instructions gave. My First Attempt started as follows

stringName = “Brittany Anne Joe” 

nameList – (“Brittany” “Anne” “Joe”) 

print (“Joe”) 

Although this gave the same results of printing my last name Joe in the program I learned to use some of Python’s functions that allows me to print my last name from a list. stringName.split automatically takes your stringName feature and divide it into separate cars for “Brittany” “Anne” “Joe”. To specify what to print from a list you need to index by specifying the number that represents your list. So “Brittany” would be 0, “Anne “would be 1, and “Joe” was 2. 

After step 1, we had to debug a prewritten code that generates the results of random wins and losses for the players. I was challenged to create a loop to generate 20 random numbers between 0-10. My unlucky value was number 5 and we had to use an if/else statement to count the number of times the unlucky number 5 was generated in the randomized list. We then did a while loop to remove the unlucky number from the list and print us a new list without the unlucky number 5. 

Doing the loops and the if/else statements were the biggest challenge following my funny blunder in the beginning as I needed to be able to recognize when to use append (n) the list within the sequence to specify that n is the list of randomly selected numbers. Additionally, to remove the unlucky numbers we had to use the remove function to remove the value 5 from the list.  Overall, with the help of classmate input and suggestions, I was able to produce the script above and understand the basics of Python. 


Comments

Popular posts from this blog

Land Classification and Ground Truthing

Module 7: Introduction to Google Earth Tours and KML Files