Py Basics Flashcards

1
Q

How can text, references, functions, calculations and more be added into one and the same Print statement?

A

by using

]]print( f’…{ calc }…{ref}…’ )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

For the Print f’-function, how are references done?

A

by using curly brackets, { }, e.g. Print( f’….{ p_varname}…{p_int_var * 12} …’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can ‘or’ be used in a while loop?

A

Enter conditional statements within brackets within the WHILE-loop;
while ( not p_num.isdigit( ) ) OR ( p_num <1 )

ref: w10.assignment_001.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to save user input to a list?

assume ages as input, end when 0, and print count, sum, avg

A

user_input = int( input( ‘Age: ‘))
ages = []
while user_input > 0:
ages.append( user_input)
user_input = int( input( ‘Next age: ‘))
print( f’sum of ages:{sum(ages)}, count ages: {len(ages)}, avg age: {sum(ages)/len(ages)}’)

ref: w10.assignment_001.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to sort a list?

A

p_list.sort( )

ref: w10.assignment_001.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to sort a list in reverse order? p_list

A

p_list.sort( reverse=True )

ref: w10.assignment_001.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to count values in a list? p_list

A

len( p_list )

ref: w10.assignment_001.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to summarise on values in a list? p_list

A

sum( p_list )

ref: w10.assignment_001.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Can an integer be traversed in a for-loop?

A

No, only a range including the same integer can

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can you traverse a for-loop with an integer?

A

p_num = int( input( “Please give me a number: “ )

for i in range( 1, p_num ):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly