Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
93 views

Python Research

The document discusses programming a video game in Python. It provides an overview of Python, noting it is easy to learn but slow and challenging to program 3D games. The document then asks how to program a video game in Python and what skills are required. It provides notes on Python syntax colors and functions. The remainder of the document contains code snippets and scripts demonstrating Python concepts like strings, functions, if/else statements, loops, lists, and files.

Uploaded by

api-528342656
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

Python Research

The document discusses programming a video game in Python. It provides an overview of Python, noting it is easy to learn but slow and challenging to program 3D games. The document then asks how to program a video game in Python and what skills are required. It provides notes on Python syntax colors and functions. The remainder of the document contains code snippets and scripts demonstrating Python concepts like strings, functions, if/else statements, loops, lists, and files.

Uploaded by

api-528342656
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

28/5/20

Begin working according to my Gantt Chart.


Discovering different types of programming sources and their according courses.
Programming Softwares Links

Python https://www.edx.org/course/basics-of-comp
uting-and-programming

28/05/20
Driving question: How can I program a small video game presenting newfound skills and
techniques for constructing and programming games?

What is python? Pros Cons

Python is a high-level - Easy to learn and - Slow


programming language use - It’s difficult to
which was first released in - Multiple platforms program a high
1991. Python’s design - A number of definition game
concept highlights code resources available - 3-dimensional game
readability with its notable - Program is or world are
use of significant Beginner-friendly challenging to create
whitespace. - There are better
programs

Driving question:
How can I program a video game using python, and what skills and techniques are required
to constructing a successful game?

Notes:
Green in python is the python string - They store text data in programs (Letters, words and
sentenced)

Purple in python is the python function

Red in python is the syntax error, meaning that you got something wrong with the script; if
you type a function that doesn’t exist, it will display a syntax error in red

Orange in python is a statement that controls the execution of the script. They control a
certain part of the script called a block.

- Python interpreter is the program that reads and runs your code
- Variable is a mailbox, where you can put something in and check the contents later
- The variable script can be executed through creating a variable, eg: msg = ‘Hello
world’ and then printing the msg, print(msg)
- You can ask the user questions or tell them to answer something using the input
function
- You can add two strings or more together by using a ‘+’ between them; however, this
will add them together so you have to manually add a space between each string like
this, “ “
- If adding a quotation mark or apostrophe, make sure that the outside ones are
different from the inside one, ‘“‘ and “‘“
- Python can also work as a powerful calculator using all the maths symbols and being
able to work
- Addition = ‘+’
Subtraction = ‘-’
Multiplication = ‘*’
Division = ‘/’
Power of = ‘* *’
- Len function counts the number of characters that are in the string
- You can make the input an integer by adding int at the beginning of the string - This
converts the string to a number
- The str function is the complete opposite of the int function, changing the integer
back to a string
- You can use ‘’’ or “”” if the string goes for multiple lines
- The if statement allows certain inputs to have different results, with the else making it
that if certain inputs aren’t in place, you will get a different result
- If the ‘if’ statement has another ‘if’ statement in it, it is called nesting. That means if
the first statement is true, then the second one will be tested.
- Elif is an abbreviation for else and if together.
- In a range, the first two numbers are what the outcome going to be, with the third
number being the gap between each number
- You can go backwards in range by having the 3rd number being a negative
- rstring can get rid of whitespaces at the right of the string
- Data structures store and organise data so it can be accessed and modified
efficiently. Lists are the simplest data structures in Python; this can be used with the
list function
- List = [ ]
- Splitting a list will make you able to count each unit in the list
- Loop initialisation is the set up for a loop
- To stop a loop we use a termination condition
- The instructions for the repetition is the body of the loop control structure
- To change the instruction, we can keep track of how many times we repeat the body,
which is the number of iterations
- while command != → This will keep repeating the script until the specific thing is
done
- while line: → Leaving it blank will make it so that you need to leave the response
blank to stop the command
- # accessing a list element - Getting specific elements in a list
# slicing from the start - Slice the list from the start, stopping at the specified number
# slicing to the end - Starts from the number and end at the final list element
# slicing in the middle - Slices between the elements
If statement:
Operation Operator

Equal to ==

Not equal to !=

Less than <

Less than or equal to <=

Greater than >

Greater than or equal to >=

Scripts:
- print(‘Hello world’) - Print script

- msg = ‘Hello world’

print(msg) - Variable script


- name = input('What is your name?')

print(name) - Input
- s = input('Enter a number: ')

number = int(s)
new_number = number - 1
print(new_number) - Integer
- print(len('Hello World!')) - len function

- raining = input("Is it raining (yes/no)? ")


if raining == "yes":
print("You should take the bus to work.")
if raining == "no":
print("You should walk to work.") - If statement

- msg = 'hello world'


print('h' in msg) - In statement
- msg = 'hello world'
print(msg.replace('l', 'X')) - Replace

- msg = "hello world"


print(msg.count("l")) - Count

- name = input('Enter your name? ')


print(name[0])
print(name[1]) - Pick characters

- name = input('Enter your name? ')


for c in name:
print(c) - For loop

- for i in "Hello":
print(i, end=" ")
print('Next line') - For loop with end function

- output = ''
for i in "Hello":
output += i
print(output)
print('Next line') - Output with loop

- for i in range(10):
print(i) - Range with loop

- x = "hello world"
print(x[:5])
print(x[6:]) - Slice script

- print(10/3)
= 3.3333333333333… - Division
- name = input('Students: ')
print('Class Roll')
roll = sorted(name.split())
for (name) in roll:
print(name) - Sorting

- i=0
while i < 10:
print(i)
i = i + 1 - While

- books = []
book = input('What book are you returning? ')
while book != '':
books.append(book)
book = input('What book are you returning? ')
books.sort()
print(books) - Looping with append

- sep = ':'
values = ['a', 'b', 'c', 'd', 'e']
print(sep.join(values)) - Separator and Join functions

Evidence:

Part 1 - Talking to your computer:


Hello, world!:
Hello to you, too:

Input script with ‘+’: (Hello with attitude)


Hello to you three!:

Part 2 - Calculating things:


Length of a string:
1-Up:

Python ^_^:
Repeaterbot:

Part 3 - Making decisions:


Open sesame!:
Access denied:

In the black:
Method of transportation:

Part 4 - Manipulating strings:


Aardvark!:
Don’t SHOUT!:

Broken keyboard:
Short/long names:

Part 5 - Repeating things:

Give me a G!:
Count to n:
Speaking backwards:

Secret agent:
Part 6 - Storing lists of values:

Halve this:

Weather report:
Sorted!:

Did I spend too much?:


Part 7 - Looping in the unknown:

Lift Off!:

Guessing game:
Up the lift:
Up the downstair:

How many words?:

One car, two car, red car, blue car!:


BaSe fOO ThE AttAcK:

Yuor biran is an azamnig thnig:


Certification of completion of course:

Course 2 - Intro to Programming 2

● The Python print function can take multiple arguments, and the joining (sep) 
and ending (end) strings can be specified. For example: 
● print("Hello", "there!") 
print('Hello', 'world', sep='-') 
print('There is no new line here', end='*') 
● print('at all!') 
print(2 + 2) 
print(20 - 7) 
print(5*6) 
print(15/2) 
print(100/2 - 3*8)  
f = open('output.txt', 'w') 
f.write("Hello, world!") 
f.write("Now we're working with files!") 
f.close() 
 
● In Python 3, the input function reads in a string provided by the user. If you 
want to convert the input to a different type, such as a float or integer, you need 
to cast to the appropriate type. For example: 
● The year variable needs to be converted to an integer so that we can perform 
the subtraction. 
● When you run examples on the website that require user input, the program will 
print out the prompt and wait for input from you. Simply type into the text box 
and hit enter. 
● name = input('What is your name? ') 
year = int(input('What year were you born in? ')) 
nyears = year - 1879 
print(name, 'was born', nyears, 'years after Einstein.') 
● There are two types of numbers in Python. Whole numbers (or integers) have 
the type int, and fractional or decimal numbers have the type float. You can 
convert between types by casting using the int and float functions: 
● ‘w’ when opening a file will write it, it will be ‘r’ on default, read mode 
● /n makes a newline character 
Review of Introduction to Programming:
Maths mix:

Robots in a line!:
Up the lift:
Guessing game:

Word2SMS:
Favourite colour:
Car colours:
Word counter:
SHOUT your orders!:

You might also like