def start_quiz(questions): score = 0 for i in range(0, len(questions)): print(questions[i]["question"] + "\n") for j in range(1, 5): print(str(j) + " " + questions[i]["option" + str(j)]) print() try: answer = int(input()) except ValueError: print(chalk.cyan('Please enter a choice between 1 and 4\n')) continue print() if 0 < answer < 5: if (questions[i]["correct_answer"] == "option" + str(answer)): print(chalk.green("Correct Answer!!!\n")) score = score + 1 else: correct_answer = questions[i]["correct_answer"] print( chalk.red("Wrong!! The Correct Answer is {}".format( questions[i][correct_answer]))) print() else: print(chalk.yellow("Invalid Choice\n")) print(chalk.yellow("Your Score is {}/{}".format(score, len(questions))))
def changeFileName(): try: print(chalk.cyan("Example: \n\n File Path: ./myfolder/pepe/file \n Rename to: ./myfolder/pepe/file2 \n\n")) fileDir = input("File Path: ") renameTo = input("Rename to: ") if fileDir != renameTo: os.rename(fileDir, renameTo) return chalk.green.bold("\nFile got renamed!") else: return chalk.red("\nFile names are similar. Please use a different name") except FileNotFoundError: return chalk.red("\nFile not found!")
def my_hook(self, d): filename = d['filename'] #type: str if d['status'] == 'finished': self.bars[filename].close() file_tuple = os.path.split(os.path.abspath(d['filename'])) #print("Done downloading {}".format(file_tuple[1])) print(chalk.green('converting to mp3... ')) if d['status'] == 'downloading': if filename not in self.bars: self.bars[filename] = tqdm( total=100, unit='mb', desc=filename[filename.rindex('/') + 1:filename.rindex('.')], bar_format=chalk.white("{l_bar}") + chalk.cyan("{bar}") + chalk.white("{r_bar}")) p = d['_percent_str'] p = p.replace('%', '') self.bars[filename].n = float(p) # check this self.bars[filename].refresh()
def start_quiz(questions): score = 0 for i in range(0, len(questions)): print('--------------------------------------------------------') print(f'Q{i+1}) {questions[i]["question"]}\n') sleep(0.3) for j in range(1, 5): print(f"({j}) {questions[i]['option'+str(j)]:30}", end='\t') sleep(0.2) if not j % 2: print() try: answer = int(input("\nEnter your option number: ")) sleep(0.3) if not 0 < answer < 5: print(chalk.yellow("Please enter a choice between 1 and 4\n")) sleep(0.4) continue except ValueError: print(chalk.cyan('Invalid Choice\n')) sleep(0.4) continue print() if (questions[i]["correct_answer"] == "option" + str(answer)): print(chalk.green("Correct Answer!!!\n")) sleep(0.4) score = score + 1 else: correct_answer = questions[i]["correct_answer"] print( chalk.red( f"Wrong!! The Correct Answer is {questions[i][correct_answer]}" )) sleep(0.4) print() print('--------------------------------------------------------\n\n') print(chalk.yellow(f"Your Score is {score}/{len(questions)}"))
common_found = 1 results = soup.find('table', {'class': 'results'}) # print(results) plant_link = soup.find( "a", { "id": "MainContentPlaceHolder_SearchResultsList_SearchResultControlLeft_0_TaxonHTMLName_0" }) planturl = plant_link['href'] print(chalk.green.bold('plant found common name'), commonNameOriginal) # now visit the site and get all the data r = requests.get(siteURL + planturl) soup = BeautifulSoup(r.text, 'html.parser') botanicalNameSpan = soup.find(id="dnn_srTitle_lblTitle") print(chalk.cyan("botanicalNameMGB ") + botanicalNameSpan.text) botanicalNameMGB = botanicalNameSpan.text plant_data = soup.find('div', {'class', 'column-right'}) for element in plant_data: row = soup.find('div', {'class', 'row'}) if (row): rowText.append(row.text) line = rowText[0].splitlines() for element in line: if element: cleaned = re.sub(' +', ' ', element) # print(cleaned) splited = cleaned.split(':')
'0', # note worthy characteristcs '0', # Problems '0', # garden uses '']) else: common_found = 1 results = soup.find('table',{'class':'results'}) # print(results) plant_link = soup.find("a",{"id":"MainContentPlaceHolder_SearchResultsList_SearchResultControlLeft_0_TaxonHTMLName_0"}) planturl = plant_link['href'] print(chalk.green.bold('plant found botanical name'),botanicalName) # now visit the site and get all the data r = requests.get(siteURL+planturl) soup = BeautifulSoup(r.text,'html.parser') botanicalNameSpan = soup.find(id="dnn_srTitle_lblTitle") print(chalk.cyan("botanicalNameMGB ") + botanicalNameSpan.text) botanicalNameMGB = botanicalNameSpan.text plant_data = soup.find('div',{'class','column-right'}) for element in plant_data: row = soup.find('div',{'class','row'}) if(row): rowText.append(row.text) line = rowText[0].splitlines() for element in line: if element: cleaned = re.sub(' +', ' ',element) # print(cleaned) splited = cleaned.split(':')