Code Challenge - Python 001 Beginners - Return half of a given string

preview_player
Показать описание
Welcome to the first code challenge, Python challenge 001. In this Python code challenge series we hope to compliment the existing Python courses on this channel. Code challenges are for people looking to sharpen their Python skills first at a beginner's level with the ambition to then move into more advanced challenges as we progress.

✨Challenge:
Given a string of any length, return 50% or half of the given string.

Notes/Constraints:
Should a given string have an odd number of letters, round down to the nearest number.

00:00 Introduction
02:06 Solution

Code Repository:

🏅 Code Challenges - Python Beginner Playlist:

🏅 Python Beginners Course:
Code repository:

🏅 Python Beginners + Course :
Code repository:

🏅 Python Intermediate Course:
Code repository:

🐱‍🏍Would you like to SUPPORT US FURTHER so that we can make even more great content - Please consider joining our members community.

👍SUBSCRIBE to get more free tutorials, courses and code snippets!
Рекомендации по теме
Комментарии
Автор

string = input("Enter a string: ")

needed = len(string)//2

for i in range(needed):
print(string[i])

KarminsLynn
Автор

for 001 this is the code i got.
solution = input("Number: ")
answer = float(solution) * float(.50)
print(answer)

ApexDefenceContracting
Автор

can't we do this str[:int(len(str)/2)]

rishabhsharma
Автор

I am not bragging as a beginner I wrote more user friendly programe by taking input and then giving half len of input .
isn't it good?

kingofartsofficial
Автор

Awesome tutorial! One question, what if I want the odd character to be in the first half of the slice instead of the second half? How would I achieve that?

RetroX
Автор

There's a formula .rsplit(' ', 1)[0] for a str with spaces

chaotic_academia