Programing

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/49

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.

50 Terms

1
New cards

Control Flow?

the order in which statements in a program (written in an imperative programming language, like Python) are executed

2
New cards

Control flow statement examples?

if statements, loop, (while, for)

3
New cards

What does EOL stand for?

End of line

4
New cards

print ("Please enter your first name")
print ("Hello", input())

Will this code execute as intended?

Yes

5
New cards

print ("Please enter the \"opposite\" value for the tangent")
opposite = input()
print ("Please enter the \"adjacent\" value for the tangent")
adjacent = input()
tangent = opposite / adjacent
print ("The tangent is ", tangent)

If the user types - in response to the prompts - the number 1, followed on the next prompt, by the number 2, the program will print: The tangent is 0.5, why or why note?

Inputs are strings. The program will fail with an error: TypeError: unsupported operand type(s) for /: 'str' and 'str'

To use them as numbers, you must first convert them.

print ("Please enter the \"opposite\" value for the tangent")
opposite = input()
print ("Please enter the \"adjacent\" value for the tangent")
adjacent = input()
tangent = int(opposite) / int(adjacent)
print ("The tangent is ", tangent)

6
New cards

What is the output of the following code?

for i in range(10, 15, 1):
    print( i, end=', ')


10,11,12,13,14,

7
New cards

for num in range(6):
      for i in range(num):
            print (num, end=" ")
            print("\n")

1

2

2

3

3

3

4

4

4

4

5

5

5

5

5

8
New cards
<p>What is wrong with this code?</p>

What is wrong with this code?

There is a TypeError

Python will interpret 1 as a callable object/function instead of an element. () are used for functions [] are used for elements in a list.

9
New cards
<p>Explain why the last two answers are wrong</p>

Explain why the last two answers are wrong

Python uses negative indexing, floats[-1] refers to the last element (3.14).floats[-2] refers to the second-to-last element (-4.5).

10
New cards
<p>Why does the second line not produce a syntax error</p>

Why does the second line not produce a syntax error

print ("Please enter the \"opposite\" value for the tangent")

The \ escapes the quotes

11
New cards

Array indices start at

0

12
New cards

What is an iterable

In Python, an iterable is any object that can be looped over (e.g., in a for loop) or passed to functions like iter() or next(). C

13
New cards

Iterable data example

string, list

14
New cards

For the code, nums = [3,4,5], what does nums[len(nums)] produce

3

15
New cards

What does this code fragment display?

for num in range(6):
      print (num, end=" ")
      print("\n")

0

1

2

3

4

5

16
New cards
<p>Why does this code produce repeating twos?</p>

Why does this code produce repeating twos?

There is no i +=1 so as a result i stays as one.

17
New cards

Is “““I love Ecor-1041””” valid?

Yes triple quotes are valid.

18
New cards

For a list of 50 items, the index of the last item is

49

19
New cards
<p>Why does this produce an index error</p>

Why does this produce an index error

because [len(nums)] will be out of range of num.

example:

nums = [10, 20, 30]

print(len(nums)) # Output: 3

20
New cards
<p>Why does this code not work?</p>

Why does this code not work?

A value for i is not initialized, will produce the error ‘i’ is not defined.

21
New cards

Will "Hello" + "World" create a new string, what is it?

Yes it will create HelloWorld

22
New cards

T/F

Every time we modify a string, Python always creates a new string and assigns the modified string value to that new string.

True

23
New cards
<p>Which expressions evaluate to false</p><ol><li><p>( len( txt ) &gt; 0 ) or ( limit - words &lt; a )</p></li><li><p>words * a &gt; limit</p></li><li><p>( a &gt; limit ) and ( len( txt ) &lt; words )</p></li><li><p>a == limit – words</p></li><li><p>not ( words &lt; limit )</p></li></ol><p></p>

Which expressions evaluate to false

  1. ( len( txt ) > 0 ) or ( limit - words < a )

  2. words * a > limit

  3. ( a > limit ) and ( len( txt ) < words )

  4. a == limit – words

  5. not ( words < limit )

True, True, False, False, False

24
New cards

what will the code range (1, 5, 2) produce?

1, 3

25
New cards

What will the code range (1,2,5) produce

1

26
New cards

What will the code range (0, 5) produce?

0,1,2,3,4

27
New cards

T/F range () requires integer arguments only?

True

28
New cards

What does this code display?


number = 5
while number >= 0:
    number -= 1
    print (number)

4

3

2

1

0

29
New cards

print (num, end=" ")

What will this line print, what does the end function do

Will print num with a space at the end

The end function is used to customize what is printed at the end of an output.

30
New cards

What does this code fragment display?

for num in range(6):
    for i in range(num):
        print (num, end=" ")
    print("")

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

31
New cards
<p><span>Which of the following Boolean expression(s) implement the following statement?</span></p><p><em>"x and y are not equal to zero, and they are either both positive or both negative"</em></p><p></p>

Which of the following Boolean expression(s) implement the following statement?

"x and y are not equal to zero, and they are either both positive or both negative"

1,2,3 apply

32
New cards

What does this print?

for num in range(6):

for i in range(num):

print (i, end=" ")

print("")

0

0 1

0 1 2

0 1 2 3

0 1 2 3 4

33
New cards

Type bool is

True or False (case sensitive)

34
New cards

What is a relational operator?

Relational operators in Python are used to compare two values or expressions. These operators evaluate the relationship between the operands and return a Boolean value: either True or False.

<p><strong>Relational operators</strong><span style="color: oklch(0.304 0.04 213.681)"> in Python are used to compare two values or expressions. These operators evaluate the relationship between the operands and return a </span><strong>Boolean value</strong><span style="color: oklch(0.304 0.04 213.681)">: either </span><code>True</code><span style="color: oklch(0.304 0.04 213.681)"> or </span><code>False</code><span style="color: oklch(0.304 0.04 213.681)">.</span></p>
35
New cards

Do print functions show up in python visualizer?

no

36
New cards

1

if 1 < 2:
 print("Hello")

2

if 1 < 2:
    print("Hello")

3

if 1 < 2:
              print("Hello")

4

if 1 < 2:
print("Hello")

Which will cause an error?

#4

37
New cards

Write a code fragment that sets a variable test to True when the float variable x is equal to 0.0 +/- 0.001

test=x<=0.001 and x>=-0.001

38
New cards
Sammy = "Sammy"
sammy = "sammy"
also_Sammy = "Sammy"

y= Sammy == sammy
x = Sammy == also_Sammy

Values of x and y?

True, False

39
New cards

Equal to symbol

==

40
New cards
<p>Values of x y and z?</p>

Values of x y and z?

3, True, False

41
New cards

Why is nothing printed?

x = 4
y = 3
if x == 3:
    print(1)
    print(2)
    if y == 3:
        print(3)
    print(4)

second if is indented

42
New cards

If there is an if/elif statement does it need to be followed by and else statement?

No

43
New cards

What is printed by the following code snippet?

x = 3
y = 4
if y == 3:
    print(1)
    print(2)
elif x == 3:
    print(3)
print(4)

3

4

44
New cards
<p>Why is this invalid?</p><p></p>

Why is this invalid?

Else can not have an argument

45
New cards

x = (1/3) == 0.3333

What is x?

False, floating point are not exact

46
New cards

What type of value will 70//5.0 return?

float

47
New cards

what type of value will 16 % 3.0 return?

float

48
New cards

Can a string be multiplied?

ex)

a = “a” * 2

Yes

49
New cards

What type of input does input() take?

Str

50
New cards