Placeholder Image

字幕列表 影片播放

由 AI 自動生成
  • Hi everyone, my name is Giovanna Proença and today we're going to talk about Problem

    大家好,我是喬瓦娜-普羅恩薩,今天我們要討論的問題是

  • Set Zero Playback Speed of CS50 Python.

    設置 CS50 Python 的零播放速度。

  • So if you have any question about programming, if you want to know about more the career or other things, please check the description below where you can schedule a 30-minute free session with us, alright?

    是以,如果您有任何關於編程的問題,如果您想了解更多關於職業或其他方面的資訊,請查看下面的說明,您可以與我們預約 30 分鐘的免費課程,好嗎?

  • And before we start, I would like to emphasize that this video solution is made for those who have already completed the assignment and want to have a second view of the code, alright?

    在開始之前,我想強調的是,這個視頻解決方案是為那些已經完成了作業並希望對代碼有第二視角的人準備的,好嗎?

  • We do not encourage plagiarism.

    我們不鼓勵抄襲。

  • So let's just start.

    那我們就開始吧。

  • Here we have some people have a habit of speaking rather quickly and it'd be nice to slow them down.

    在這裡,有些人有語速過快的習慣,最好能讓他們慢下來。

  • So allow YouTube 0.75 playback speed or even by having them pause between words.

    是以,請允許 YouTube 以 0.75 的速度播放,甚至讓他們在單詞之間暫停。

  • In a file called playback.py, implement a program in Python that prompts the user for input and then outputs the same input replacing each space with three periods.

    在名為 playback.py 的文件中,用 Python 實現一個程序,提示用戶輸入,然後輸出相同的輸入,將每個空格替換為三個句點。

  • So here we have the example we have here.

    是以,我們這裡就有這樣一個例子。

  • Once we run the code, we're going to write a message to user and we're going to prompt the message with three periods instead of the white space, okay?

    運行代碼後,我們將向用戶寫入一條資訊,並用三個句號代替空格,好嗎?

  • So let's start thinking about the things that we need.

    所以,讓我們開始考慮我們需要的東西吧。

  • I already did here a pseudocode, alright?

    我已經在這裡做了一個偽代碼,好嗎?

  • So basically we need to get input from the user, then we're going to change white space for three dots and then we're going to print the output.

    是以,基本上我們需要獲取用戶的輸入,然後將空白處換成三個點,最後打印輸出。

  • So how can we do the first test?

    那麼,如何進行第一次測試呢?

  • How can we get input from the user?

    如何獲取用戶的意見?

  • Let's see this explanation.

    讓我們看看這個解釋。

  • Basically the function input allows us to ask questions to the user and the answer that the user typed in, we can start in a variable.

    基本上,輸入功能允許我們向用戶提問,而用戶輸入的答案可以從一個變量開始。

  • For example, if we want to ask the name of the user, we can do username equals to input.

    例如,如果要詢問用戶的姓名,我們可以將 username 等於 input。

  • What's your name?

    你叫什麼名字?

  • And it will be prompt in the terminal.

    終端會有提示。

  • The user can write his name.

    用戶可以寫下自己的名字。

  • If the user types in Giovanna, the variable username will start Giovanna.

    如果用戶輸入 Giovanna,變量 username 將以 Giovanna 開始。

  • Since the answer is stored in a variable, we can use this answer in our code.

    由於答案存儲在一個變量中,我們可以在代碼中使用這個答案。

  • So like we saw, we can use the input function, alright?

    就像我們看到的那樣,我們可以使用輸入函數,好嗎?

  • So let's grab the message from the user.

    是以,讓我們從用戶那裡獲取信息。

  • So I'm going to create here a variable called msg to start a message and we're going to use input here, okay?

    是以,我要在這裡創建一個名為 msg 的變量來開始一條資訊,我們要在這裡使用輸入法,好嗎?

  • If you want, you can type something in here inside the input, but in our case, I won't type anything, alright?

    如果你願意,可以在輸入框內輸入一些內容,但就我們的情況而言,我不會輸入任何內容,好嗎?

  • So we're going to see here that if we do python playback.py, it's going to appear this cursor where we can type in this is CS50 and this message is stored in our code, okay?

    是以,我們將在這裡看到,如果我們執行 python playback.py,就會出現這個遊標,我們可以在其中輸入這是 CS50,這條資訊就會存儲在我們的代碼中,好嗎?

  • If we print the output, it will print the same message.

    如果我們打印輸出,會打印出相同的資訊。

  • If we do print a message, it will print this, this is CS50, okay?

    如果我們打印一條資訊,它會打印這個,這是 CS50,好嗎?

  • It's printing the same thing.

    打印的是一樣的東西。

  • But this is not the goal of our problem.

    但這並不是我們解決問題的目的。

  • The goal of our problem is to change the whitespace for three periods.

    我們的目標是改變三個時段的空白。

  • So how can we do this?

    那麼,我們如何才能做到這一點呢?

  • We're going to use the replace function.

    我們將使用替換功能。

  • Let's understand how this replace function works.

    讓我們來了解一下替換功能的工作原理。

  • The replace method replaces a specified phrase with another specified phrase.

    replace 方法將指定的短語替換為另一個指定的短語。

  • If we will have a variable txt equals to I like bananas and we want to change bananas to apple, we can use the replace method to make this change for us.

    如果我們有一個變量 txt 等於 "我喜歡香蕉",而我們想把香蕉改成蘋果,我們可以使用 replace 方法來進行更改。

  • We can do txt.replace and inside the parenthesis we put the word that we want to change, in our case bananas, with the new word that we want to replace, in our case apples, and our string txt will become I like apples.

    我們可以使用 txt.replace,在括號內輸入要更改的單詞(在我們的例子中是香蕉)和要替換的新單詞(在我們的例子中是蘋果),這樣我們的字符串 txt 就會變成 I like apples。

  • So in our case, instead of replacing bananas to apples, we're going to replace whitespace for three dots, okay?

    是以,在我們的例子中,不是將香蕉替換為蘋果,而是將空格替換為三個點,好嗎?

  • So let's create a new variable I'm going to call new message, alright?

    所以,讓我們創建一個新變量,我稱之為 new message,好嗎?

  • And in here we're going to use the previous variable that was storing the message, so msg. and now we're going to use the method replace, okay?

    在這裡,我們將使用之前存儲資訊的變量 msg。

  • So .replace and what we want to replace?

    那麼......替換,我們要替換什麼?

  • We have to pass two arguments, two parameters.

    我們必須傳遞兩個參數。

  • The first one will be the word or the character that we want to replace.

    第一個是我們要替換的單詞或字元。

  • So in our case we want to replace whitespace.

    是以,在我們的例子中,我們要替換空白。

  • So in here we're going to use quotation mark and click space in the middle, alright?

    所以在這裡我們要使用引號,然後點擊中間的空格,好嗎?

  • So we can signalize that we want to replace the whitespace.

    是以,我們可以發出信號,表示要替換空白。

  • And we want to replace by what?

    我們想用什麼來替代?

  • So in here we're going to use three dots inside.

    所以在這裡,我們要在裡面使用三個點。

  • So this means that everything that is whitespace will become three dots, okay?

    這意味著,所有空格都將變成三個點,明白嗎?

  • And finally we're going to print this new variable that we are storing the new message, okay?

    最後,我們要打印這個存儲新資訊的新變量,好嗎?

  • So let's try it out.

    那就試試看吧。

  • So if we do python playback.py and if we type in this is cs50.

    是以,如果我們輸入 python playback.py,然後輸入 cs50。

  • Now we have the three periods instead of the whitespaces, okay?

    現在我們用三個句號代替空格,好嗎?

  • So this is it for the function.

    功能就到此為止。

  • Let's do check50 and see if it's working.

    讓我們檢查 50,看看它是否有效。

  • So if we take a look in here, we took all green.

    是以,如果我們看一下這裡,就會發現這裡全是綠色。

  • So this means that our code is running fine, okay?

    這意味著我們的代碼運行正常,好嗎?

  • So this is it for the playback problem.

    重放問題就解決了。

  • If you have any questions, please let us know, send us a message or a comment, subscribe to our channel, please give us a thumbs up and see you in the next video, alright?

    如果您有任何問題,請告訴我們,給我們留言或評論,訂閱我們的頻道,請為我們豎起大拇指,下期視頻再見,好嗎?

  • Bye bye!

    再見

Hi everyone, my name is Giovanna Proença and today we're going to talk about Problem

大家好,我是喬瓦娜-普羅恩薩,今天我們要討論的問題是

字幕與單字
由 AI 自動生成

單字即點即查 點擊單字可以查詢單字解釋

A2 初級 中文 美國腔

問題集 0:播放速度 | 解決方案(CS50 Python) (PROBLEM SET 0: PLAYBACK SPEED | SOLUTION (CS50 PYTHON))

  • 6 0
    林照翌 發佈於 2024 年 09 月 30 日
影片單字