100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Python Basics Test Questions with All Answers $13.19   Add to cart

Exam (elaborations)

Python Basics Test Questions with All Answers

 14 views  0 purchase
  • Course
  • Python Basics
  • Institution
  • Python Basics

Python Basics Test Questions with All Answers Use two argument specifiers to print that the "name" is an "age" of 20. - Answer-name = "Tim" age = 20 print("%s is %d years old." % (name, age)) For list *mylist* of [1, 2, 3], print "A list:" followed by the list, using an argument specifier. -...

[Show more]

Preview 2 out of 7  pages

  • August 12, 2024
  • 7
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • Python Basics
  • Python Basics
avatar-seller
Perfectscorer
Python Basics Test Questions with
All Answers

Use two argument specifiers to print that the "name" is an "age" of 20. - Answer-name =
"Tim"
age = 20
print("%s is %d years old." % (name, age))

For list *mylist* of [1, 2, 3], print "A list:" followed by the list, using an argument specifier.
- Answer-mylist = [1, 2, 3]
print("A list: %s" % mylist)

Four basic argument specifiers: - Answer-1. %s - String

2. %d - Integers

3a. %f - Floating point numbers
3b. %.<numberofdigits>f - Floating point numbers with a fixed amount of digits to the
right of the dot.

4a. %x - Lowercase hexidecimal integer
4b. %X - Uppercase hexidecimal integer

Exercise:

-Write a format string which prints out the data using the following syntax:
*Hello John Doe. Your current balance is $53.44*

-Code given:
data = ("John", "Doe", 53.44)
format_string = ?

print(format_string % data) - Answer-Answer:

format_string = "Hello, %s %s. Your current balance is $%s"

Print the length of variable astring, "Hello world!" - Answer-astring = "Hello world!"

print(len(astring))

, Find the location of the letter o in the variable astring, "Hello world!" - Answer-astring =
"Hello world!"

print(astring.index("o"))

Count how many times l appears in the variable astring, "Hello world!" - Answer-astring
= "Hello world!"

print(astring.count("l"))

Print a slice of the variable astring, "Hello world!", starting at index 3 and ending at index
6. - Answer-astring = "Hello world!"

print(astring[3:7])

Print variable astring, "Hello world!", backwards - Answer-astring = "Hello world!"

print(astring[::-1])

Print variable astring, "Hello world!", in all lowercase vs. all uppercase - Answer-astring
= "Hello world!"

All lowercase:
print(astring.lower())

All uppercase:
print(astring.upper())

Print a slice of the variable astring, "Hello world!", starting at index 3 and ending at index
6, skipping every other letter (increment of 2) - Answer-astring = "Hello world!"

print(astring[3:7:2])

Print true or false for the variable astring, "Hello world!", checking if it starts with "Hello"
and ends with "asdfghjkl" - Answer-astring = "Hello world!"

print(astring.startswith("Hello"))

print(astring.endswith("asdfghjkl"))

Split the two terms in the variable astring, "Hello world!" - Answer-astring = "Hello
world!"

afewwords = astring.split(" ")

Boolean example with x = 2 and comparisons to 2, 3, and less than 3 - Answer-x = 2

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

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

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

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 Perfectscorer. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $13.19. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

76747 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$13.19
  • (0)
  Add to cart