6 Hours of python

5.0(1)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/27

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

28 Terms

1
New cards

How do you print the same text multiple times?

By using a * and a number

eg. Print(“Gyat” * 3)

2
New cards

What are the 4 main variable types

integer - whole numbers (eg 1, 2, 3)

float - decimal points (eg 1.0, 2.5, 3.69)

string - text (eg hello world)

boolean - true or false

3
New cards

What must you be careful when using if else statements?

There is a colon (:) (and therefore indentation)

4
New cards

What is the difference between , and + when using the print function?

A comma will cause a space between the values vbeing printed whereas a + will cause them to print directly next to eachother

5
New cards

How do you limit the number of decimal points in Python?

By using the round fucntion (literally “round()”) or %.f

<p>By using the round fucntion (literally “round()”) or %.f</p>
6
New cards

What is the difference between / and // (arithmic)

/ will give a float while // gives an intiger

7
New cards

What does % do (arithmic)

Gives the remainder of the devision

8
New cards

What is the difference between * and **

  • * multiplies while ** makes it to the power

9
New cards

How do if, elif and else statements work together?

If condition 1 is true

do…

elif condition 2 is true ( and 1 is false)

do…

else (both condition 1 and 2 false)

do…

<p>If condition 1 is true</p><p>do…</p><p>elif condition 2 is true ( and 1 is false)</p><p>do…</p><p>else (both condition 1 and 2 false)</p><p>do…</p>
10
New cards

What does the “not” opetation do?

Converts boolean variables to the opposite (E.g true=flase)

11
New cards

What is the greater/less than or equal to sign in python

>= / <=

12
New cards

What does the len() function do?

Gives the number of characters

13
New cards

How do i make an input not case sensetive

lowercase_input = user_input.lower()

(The variable is equal to the previous input but it is not all lower case, the same can be done with .upper())

14
New cards

When using the print function, what foes f before quotation marks do?

print(f”text”) allows for variables to be placed inside the quotation marks as lond as they are in {curlyBrackets}

15
New cards

what does != mean?

not equal to ( while != “pink”, do …)

16
New cards
<p>What is the difference between the first codes?</p>

What is the difference between the first codes?

The second code with the indentation will print the total each time it adds a number while the first code will print the sum of all the numbers

<p>The second code with the indentation will print the total each time it adds a number while the first code will print the sum of all the numbers</p>
17
New cards
<p>Will x or y reach 1 first?</p>

Will x or y reach 1 first?

y (will reach 1 first)

18
New cards
<p>How do you make a system that will print the highest number?</p>

How do you make a system that will print the highest number?

(using a nested loop)

<p>(using a nested loop)</p>
19
New cards

What are the 2 ways to check if a number is in the list?

The ‘in’ operator - will provide a boolean value (true/false)

Or using .index - will provide the first location of the number (eg if the number comes up twice in a list it will only show the first location)

20
New cards

What is the difference between lists and tuples

Tuples cant be ammended

21
New cards
<p>What is the shorthand was of (image)</p>

What is the shorthand was of (image)

x,y,z = coordinates

22
New cards

What is def used for in python? and how would it be used

To define a function, will allow a function to be “used” whenever the variable name is called upon

23
New cards

What do the peramiters in def() do?

They act as variables, which have to be given a value

24
New cards

What is the except function used for?

To help debug code/ prevent if from crashing

25
New cards

What are classes used for in python?

To define new types

26
New cards

What is PascalCase

A naming convention where every first letter of the word is capitalised

27
New cards

How do you make a class inherit all the code from another class?

class newVariable(inheritingVariable)

28
New cards

What are modules used for?

To organise code into multiple sections