[SHORT ANSWER] Assume the string variables firstName and userID are assigned
with values. use string slicing and concatenation to create a username based on the
first two letters of the firstName, concatenated with the last four digits of the userID as
shown in the example below.
For Example: Suppose firstName = "Mary" and userID = "W12345678" then, the
username should be:
SHORT ANSWER Assume variable gpa has already been assigned a value. Write
python code that displays invalid GPA if the value associated with variable gpa is not in
the range [0,4] - Answer -if gpa < 0 or gpa > 4:
print("Invalid GPA")
Which type of error prevents the program from running?
human
syntax
grammatical
logical - Answer -syntax
The smallest storage location in a computer's memory is known as a
switch
byte
ketter
bit - Answer -bit
A Python line comment begins with ________.
a. /*
b. $$
c. //
d. # - Answer -d. #
,Which of the following are valid camel case identifier naming styles (Choose all that
apply)?
(a) dollar_amount
(b) dollarAmount
(c) dollar$Amount
(d) amtDollar
(e) dollarAmt$
(f) dollarAmt
(g) amountDollar
(h) Dollar_Amount - Answer -(b) dollarAmount
(d) amtDollar
(f) dollarAmt
(g) amountDollar
Assume the following:
val = 99
val += 1
Match the code with its output:
a. print('The value is', 'val')
b. print('The value is', val)
print("The value is:", 'val')
The value is val
The value is 100
The value is: val - Answer -(a) The value is val
(b) The value is 100
(c) The value is: val
Match the relational operators with its meaning:
a. >
b. <
c. >=
d. <=
e. ==
f. != - Answer -a. Greater than
b. less than
c. Greater than or equal to
d. Less than or equal to
e. Equal to (equality operator)
f. Not equal to
Which of the following will assign a random integer in the range of 1 through 50 to the
variable number?
, (a) number = random(range(1, 50))
(b) random(1, 50) = number
c) number = random.randint(1, 50)
(d) randint(1, 50) = number - Answer -c) number = random.randint(1, 50)
x < y or z > x What is the result of the following Boolean expression, given that x = 5, y
= 3, and z= 8?
What is the result of the following Boolean expression, given that x = 5, y = 3, and z =
8?
x < y or z > x
(a) False
(b) 8
(c) True
(d) 5 - Answer -(c) True
Consider the following statements. If the input is 85, the output of the following code will
be:
score=0
grade="Unknown"
score = int(input ("Enter a score: "))
if score >= 90:
grade = "A"
if score >= 80:
grade "B"
if score >= 70:
grade = "C"
if score >= 60:
grade = "D"
else:
grade = "F"
print (grade)
C
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller millyphilip. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $12.49. You're not tied to anything after your purchase.