Day 30: 100 Days of Code: f-strings

preview_player
Показать описание
The `f` stands for format...not whatever you were thinking. Change the way you combine strings and variables with f-strings.

00:00 f-strings
02:48 Local variables
04:44 the power of f
05:48 Alignment
07:28 Common errors
08:32 Fix my code
08:43 Day 30 challenge
09:01 Share your code
09:16 Next up
Рекомендации по теме
Комментарии
Автор

Why is it easier for me to follow along with you than an entire semester of college? Thanks David!

OldSchoolIntegrity
Автор

print("30 days Down")

for i in range(1, 31):
days = input(f"Day {i}:\n")
print(f"You thought day {i} was {days}".center(50))

tounsimed
Автор

Struggling a bit in the last part of making the align center for the whole statement at first. Then try some trial and error and finally got the answer.

Got what you want methinks but maybe not in the best way.

print("30 Days Down")
print()
for i in range(1, 31):
print(f"Day {i} of 30")
opinion = input("what do you think of the following Day?:")
DayChallenge = f"You thought Day {i} was {opinion}"
print(f"{DayChallenge: ^50}")

wittx
Автор

This is was insightful. I added an extra few lines of code to ask the user what they had learned on that day.

import time

print("30 days down - What did you think?")
print()
time.sleep(1)

print("Please tell us what you thought of each day.")
print()
time.sleep(1)

for i in range(1, 31):
userThought = input(f"Day {i}:\n")
print()
userResponse = f"You thought Day {i} was"
print(f"{userResponse:^35}")
print(f"{userThought:^35}")
print()
userLearn = input("What did you learn?:\n")
print()
userLearned = "That's excellent! You learned"
print(f"{userLearned:^35}")
print(f"{userLearn:^37}")
print()
time.sleep(1)

RichOnStream
Автор

Thanks david! I really learn a lot from you.

print("30 days down - What do you think?\n")
for i in range(1, 31):
userInput = input(f'Day {i}:\n>')
days = f"You thought day {i} was"
print()
print(f"{days:^45}")
print(f"{userInput:^45}\n")

Tan
Автор

print()
print("30 Days Down - What did you think?")
for i in range(1, 30):
response = input(f"\033[31mDay {i}:\033[0m\n")
print(f"You thought Day {i} was {response}".center(40))

abhi
Автор

for i in range(1, 31):
print(f'Day {i:>2}:')
x= str(input(f'The Day {i} was for you? : '))
print(f'You thought Day {i} was {x}')
print('')

print('*** Finished ***')

matfrei
Автор

print("30 days passed what was your experince with the bald guy?")
print("")
for i in range (1, 31):
days = f"you thougth day {i} was "
answer = input(f" day {i}\n>")
coma = "^"
print("")
print(f"{days: ^45}")
print("")
print(f"{coma: ^45}")
print(f"{answer: ^45}")

HawasMusazai
Автор

print("30 Days Down - What did you think?\n")
for i in range(1, 31):
Feedback=input(f"Day {i} : \n")
Response= f"You thought Day {i} is {Feedback}"
print(f"\033[32m {Response:^50} \033[0m")

QBrd-fi
Автор

I am curious to if one of these methods are normally more used than others ? The part where you talk about "The power of f" that starts @4:45 is to me the easiest way to use out of these methods. Is it just a personal preference or do they actually differ in use and it just went completely over my head? Thanks again! Love this course and the humor is excellent 😄

kristiankningsberg
Автор

import os, time
print("DAY 30 CHALLENGE")
for n in range(1, 31):
ask = input(f"\033[31mWhat did you think of Day {n: ^2}?\033[0m\n")
print(f"""\033[34mAh, I see. You thoughts on Day {n} was {ask}

\033[0m""")
time.sleep(2)
os.system("clear")

hhhjh
Автор

print("100 DAYS OF CODE PYTHON")
print("\n")
for i in range(1, 100):
x = input(f"Day {i}, what did you thought?:\n")
print("")
print(f"You though that the {i} Day was {x}")

Makisan
Автор

print("""
30 DAYS DOWN! - THOUGHTS SO FAR?
""")

i = 0
while i <= 29:
i += 1
thoughts = input(f"""
Day {i}?:


""")
print(f"""
Your thoughts on (Day {i}) was: {thoughts}

""")

atomix
Автор

I did the problem, and then I saw the solution because I wanted to change a couple of things, but I regretted it.

Anyways, I think it is better to use (f"""argument """) instead of f{var^x}...

print("\033[36m", "Our thought about Replit's 100 Day Of Code course", sep="")
print("\033[37m", )
username = input("What is your name?: ")
far = int(input("How many days do you have in this course?: "))
print(" ")

import os, time
for i in range(1, far + 1):
print(f"Day {i}!")
print(" ")
opinion = input(f"What did you think about day {i}?: ")
learn = input(f"What did you learn {username}?: ")
structure = f"You thought {opinion}, and you learned {learn}"
print(" ")
print(f"{structure:^100}")
time.sleep(4)
os.system("clear")
print("\033[36m", "That was a great experience...", sep="")
print(f"We should never stop learning! {username}")

Leerata