Mastery Topics[3,6]

--Originally published at Program

3. Python has five standard data types −

  • Numbers
  • String
  • List
  • Tuple
  • Dictionary

6. In the context of programming, a function is a named sequence of statements that performs a computation. When you define a function, you specify the name and the sequence of statements. Later, you can “call” the function by name. We have already seen one example of a function call: >>> type(32) <type ‘int’=””> The name of the function is type. The expression in parentheses is called the argument of the function. The result, for this function, is the type of the argument. It is common to say that a function “takes” an argument and “returns” a result. The result is called the return value.

credit:

https://www.tutorialspoint.com/python/python_variable_types.htm

http://greenteapress.com/thinkpython/thinkpython.pdf


Mastery Topics(4-5)

--Originally published at Program

  1. Basic output (print): To print something that you want you use print and the the thing you want to see on screen in () parenthesis.
  2. Basic user input (text based): Input is where the user gives their input for the program to run.

credit:

myself


Mastery Topics(1-2)

--Originally published at Program

  1. Comments: As programs get bigger and more complicated, they get more difficult to read. Formal languages are dense, and it is often difficult to look at a piece of code and figure out what it is doing, or why. For this reason, it is a good idea to add notes to your programs to explain in natural language what the program is doing. These notes are called comments, and they start with the # symbol: # compute the percentage of the hour that has elapsed percentage = (minute * 100) / 60
  2. Python conventions (Zen of Python but others for other languages): is a collection of 20 python principles on which python is based on.                                                 Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren’t special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one—and preferably only one—obvious way to do it.
    Although that way may not be obvious at first unless you’re Dutch.
    Now is better than never.
    Although never is often better than right now.[5]
    If the implementation is hard to explain, it’s a bad idea.
    If the implementation is easy to explain, it may be a good idea.
    Namespaces are one honking great idea—let’s do more of those!

Credit:

https://en.wikipedia.org/wiki/Zen_of_Python

http://greenteapress.com/thinkpython/thinkpython.pdf


WSQ-05

--Originally published at Program

You will go back and do WSQ01 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.

You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

if you wanna see an easier way go here:

https://chinbrow.wordpress.com/2017/01/30/calculator/


WSQ-04

--Originally published at Program

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.


WSQ-03

--Originally published at Program

Write a program that picks a random integer in the range of 1 to 100.

There are different ways to make that happen, you choose which one works best for you.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.


WSQ-06

--Originally published at Program

Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).