100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

PYTHON CODING QUESTIONS AND ANSWERS TO HELP IN (Problem Solving & Understanding) 100% VERIFIED

Rating
-
Sold
-
Pages
29
Uploaded on
10-12-2024
Written in
2024/2025

PYTHON CODING QUESTIONS AND ANSWERS TO HELP IN (Problem Solving & Understanding) 100% VERIFIED

Institution
Python Coding
Course
Python Coding










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Python Coding
Course
Python Coding

Document information

Uploaded on
December 10, 2024
Number of pages
29
Written in
2024/2025
Type
Exam (elaborations)
Contains
Unknown

Subjects

Content preview

PYTHON CODING QUESTIONS AND
ANSWERS TO HELP IN (Problem Solving
& Understanding) 100% VERIFIED .
What is indexing used for in Python?
"Indexing" is used when referring to an element of an inerrable by its position within
the inerrable. This is done through indexing [ ].
CQ: Try creating a substring based off of the first word or name in the sentence.

use the following variable:

name = "Johnny Appleseed"

Once finished.

Try creating a substring based off of the last word or name in the sentence.

Once finished.

Next, create a weird name from the variable by leaving the first and last name in
but making it so it skips every other letter.

Lastly, reverse the name or text of the value in the variable by making it read
In order to write a line of code that can slice a specific part of the name such as
"Johnny" by itself,

We'll use the following code:

first_name = name[0:6]

or

,first_name = name[:6]

Then...

print(first_name)

Now, in order to write a line of code that can slice the last word or name such as
"Applseed".

We'll use the following code:

last_name = name[7:17]

or

last_name = name[7:]

Then...

print(last_name)

Note: For slicing we'll use the colon to snip a part of the text in the variable by listing
the number the letter starts with which is always "0" and "6" since we'll always take
an extra character at the end or you can also see it as there's 6 letters in "Johnny" but
we still always start with zero.

Next, in order to create a weird name we'll need to add a third colon instead of just
the two we've been using previously.

We'll use the following code:

funny_name = name[0:16:2]

or

, funny_name = name[::2]

print(funny_name)

Note: As you can see the program will skip every other letter in "Johnny Appleseed".

"Johnny Appleseed"
"J h n p l s e "

Lastly, in order to create a reversed name we'll use negative numbers. Similar to first
puzzle just counting starting from the last letter instead of the first.

reversed_name=[-1:-17:-1]

or

reversed_name=[::-1]

print(reversed_name)

Note: When counting backwards we'll always count in the negatives. Due to counting
in the negatives there's no need to count zero since -0 isn't an actual number so we'll
default into -1 as the first letter reversed counting backwards in the last colon.
CQ: Try removing everything but the name of from the website link from the value
in the variable.

use the following variable:

website = "https://google.com"
In order to remove everything but the name of the website we'll use the slice option.

For "Slice" it's a little bit different so we'll use a comma instead of a colon for slice
unlike the indexing.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
saraciousstuvia WALDEN UNIVERSITY
View profile
Follow You need to be logged in order to follow users or courses
Sold
558
Member since
3 year
Number of followers
380
Documents
11349
Last sold
12 hours ago
BRIGHTEST IDEAS EDUCATIONAL WORLD

Welcome to the best educational world with the brightest,amazing and all complete study materials. I wish you great,easy learning and success through out your course. Kindly message me if you cant find your tutorials

4.0

114 reviews

5
61
4
20
3
17
2
3
1
13

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions