ronantakizawa/codereview-bench huggingface dataset:
Repository: Python-World/python-mini-projects
File: projects/Number guessing game/main.py (Python)

Code before:
import random 
  
print("Number guessing game") 
  
# randint function to generate the  
# random number b/w 1 to 9 
number = random.randint(1, 9) 
  
# number of chances to be given  
# to the user to guess the number  
# or it is the inputs given by user 
# into input box here number of   
# chances are 5 
chances = 0
  
print("Guess a number (between 1 and 9):")  
  
# While loop to count the number 
# of chances 
while chances < 5: 
      
    # Enter a number between 1 to 9  
    guess = int(input()) 
      
    # Compare the user entered number   
    # with the number to be guessed  
    if guess == number: 
          
        # if number entered by user   
        # is same as the generated   
        # number by randint function then   
        # break from loop using loop  
        # control statement "break" 
        print("Congratulation YOU WON!!!") 
        break
          
    # Check if the user entered   
    # number is smaller than   
    # the generated number  
    elif guess < number: 
        print("Your guess was too low: Guess a number higher than", guess) 
  
    # The user entered number is   
    # greater than the generated  
    # number              
    else: 

Review comment (suggestion):
For printing the number of attempts the user takes, replace this with:
```python
while True:
```

Code after:
import random

print("Number guessing game")

# randint function to generate the
# random number b/w 1 to 9
number = random.randint(1, 9)

# number of chances to be given
# to the user to guess the number
# or it is the inputs given by user
# into input box here number of
# chances are 5
chances = 0

print("Guess a number (between 1 and 9):")

# While loop to count the number
# of chances
while True:

    # Enter a number between 1 to 9
    guess = int(input())

    # Compare the user entered number
    # with the number to be guessed
    if guess == number:

        # if number entered by user
        # is same as the generated
        # number by randint function then
        # break from loop using loop
        # control statement "break"
        print(
            f'CONGRATULATIONS! YOU HAVE GUESSED THE \
            NUMBER {number} IN {chances} ATTEMPTS!')
        # Printing final statement using the f-strings method;
        break

    # Check if the user entered
    # number is smaller than
    # the generated number
    elif guess < number:
        print("Your guess was too low: Guess a number higher than", guess)

    # The user entered number is
Repository: Python-World/python-mini-projects
File: projects/Number guessing game/main.py (Python)

Code before:
# number of chances to be given  
# to the user to guess the number  
# or it is the inputs given by user 
# into input box here number of   
# chances are 5 
chances = 0
  
print("Guess a number (between 1 and 9):")  
  
# While loop to count the number 
# of chances 
while chances < 5: 
      
    # Enter a number between 1 to 9  
    guess = int(input()) 
      
    # Compare the user entered number   
    # with the number to be guessed  
    if guess == number: 
          
        # if number entered by user   
        # is same as the generated   
        # number by randint function then   
        # break from loop using loop  
        # control statement "break" 
        print("Congratulation YOU WON!!!") 
        break
          
    # Check if the user entered   
    # number is smaller than   
    # the generated number  
    elif guess < number: 
        print("Your guess was too low: Guess a number higher than", guess) 
  
    # The user entered number is   
    # greater than the generated  
    # number              
    else: 
        print("Your guess was too high: Guess a number lower than", guess) 
          
    # Increase the value of chance by 1 
    chances += 1
          
          
# Check whether the user   
# guessed the correct number  
if not chances < 5: 
    print("YOU LOSE!!! The number is", number)

Review comment (suggestion):
And replace this piece of code with:
```python
print(f'CONGRATULATIONS! YOU HAVE GUESSED THE NUMBER {number} IN {chances} ATTEMPTS!')
#Printing final statement using the f-strings method;
```

Code after:
# number of chances to be given
# to the user to guess the number
# or it is the inputs given by user
# into input box here number of
# chances are 5
chances = 0

print("Guess a number (between 1 and 9):")

# While loop to count the number
# of chances
while True:

    # Enter a number between 1 to 9
    guess = int(input())

    # Compare the user entered number
    # with the number to be guessed
    if guess == number:

        # if number entered by user
        # is same as the generated
        # number by randint function then
        # break from loop using loop
        # control statement "break"
        print(
            f'CONGRATULATIONS! YOU HAVE GUESSED THE \
            NUMBER {number} IN {chances} ATTEMPTS!')
        # Printing final statement using the f-strings method;
        break

    # Check if the user entered
    # number is smaller than
    # the generated number
    elif guess < number:
        print("Your guess was too low: Guess a number higher than", guess)

    # The user entered number is
    # greater than the generated
    # number
    else:
        print("Your guess was too high: Guess a number lower than", guess)

    # Increase the value of chance by 1
    chances += 1
Repository: Python-World/python-mini-projects
File: projects/convert pdf to text/converter1.py (Python)

Code before:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 16:38:39 2020

@author: Admin
"""

import PyPDF2

pdfobj = open('/path/to/pdf', 'rb') #Provide the path for your pdf here

pdfread = PyPDF2.PdfFileReader(pdfobj)

x = pdfread.numPages


for i in range(x):
    pageObj = pdfread.getPage(i)
    with open('/path/to/txt', 'a+') as f: #Provide the path for the output text file
        f.write((pageObj.extractText()))
    print(pageObj.extractText()) #This just provides the overview of what is being added to your output, you can remove it if want
                                    
    
    

pdfobj.close()  

Review comment (suggestion):
ask user input for pdf file
```suggestion
file_path =input('FilePath:')
pdfobj = open(file_path 'rb') #Provide the path for your pdf here
```

Code after:
# -*- coding: utf-8 -*-


import PyPDF2
import os


if(os.path.isdir("temp") == False):
    os.mkdir("temp")
    
txtpath = ""
pdfpath = ""



pdfpath = input("Enter the name of your pdf file - please use backslash when typing in directory path: ")   #Provide the path for your pdf here
txtpath = input("Enter the name of your txt file - please use backslash when typing in directory path: ")   #Provide the path for the output text file  

BASEDIR = os.path.realpath("temp") # This is the sample base directory where all your text files will be stored if you do not give a specific path
print(BASEDIR)


if(len(txtpath) == 0):
    txtpath = os.path.join(BASEDIR,os.path.basename(os.path.normpath(pdfpath)).replace(".pdf", "")+".txt")
pdfobj = open(pdfpath, 'rb')

pdfread = PyPDF2.PdfFileReader(pdfobj)

x = pdfread.numPages


for i in range(x):
    pageObj = pdfread.getPage(i)
    with open(txtpath, 'a+') as f: 
        f.write((pageObj.extractText()))
Repository: Python-World/python-mini-projects
File: projects/convert pdf to text/converter1.py (Python)

Code before:
# -*- coding: utf-8 -*-


import PyPDF2


BASEDIR = "C:\Documents\pdf_to_text\output.txt" # This is the sample base directory where all your text files will be stored if you do not give a specific path
txtpath = ""
pdfpath = ""



pdfpath = input("Enter the name of your pdf file - please use backslash when typing in directory path: ")   #Provide the path for your pdf here
txtpath = input("Enter the name of your txt file - please use backslash when typing in directory path: ")   #Provide the path for the output text file  

if(len(txtpath) == 0):
    txtpath = BASEDIR
pdfobj = open(pdfpath, 'rb') 

pdfread = PyPDF2.PdfFileReader(pdfobj)

x = pdfread.numPages


for i in range(x):
    pageObj = pdfread.getPage(i)
    with open(txtpath, 'a+') as f: 
        f.write((pageObj.extractText()))
    print(pageObj.extractText()) #This just provides the overview of what is being added to your output, you can remove it if want
                                    
    
    

Review comment (suggestion):
don't use any static file path
use temp directory in same folder because everyone do not have same path(Create if not exists)
```suggestion
BASEDIR = "pdf_to_text\output.txt"
```

Code after:
# -*- coding: utf-8 -*-


import PyPDF2
import os


if(os.path.isdir("temp") == False):
    os.mkdir("temp")
    
txtpath = ""
pdfpath = ""



pdfpath = input("Enter the name of your pdf file - please use backslash when typing in directory path: ")   #Provide the path for your pdf here
txtpath = input("Enter the name of your txt file - please use backslash when typing in directory path: ")   #Provide the path for the output text file  

BASEDIR = os.path.realpath("temp") # This is the sample base directory where all your text files will be stored if you do not give a specific path
print(BASEDIR)


if(len(txtpath) == 0):
    txtpath = os.path.join(BASEDIR,os.path.basename(os.path.normpath(pdfpath)).replace(".pdf", "")+".txt")
pdfobj = open(pdfpath, 'rb')

pdfread = PyPDF2.PdfFileReader(pdfobj)

x = pdfread.numPages


for i in range(x):
Repository: Python-World/python-mini-projects
File: projects/Unstructured Supplemenrary  Service Data/ussdtim.py (Python)

Code before:
			time.sleep(5)
			print("Upgrading...")
			exit( )
		elif prompt == 2:
			time.sleep(5)
			print("Migrating...")
			exit( )
		elif prompt == "#":
			options_menu( )
		else:
			sys.exit( )

def balance ( ):
	print("ACCOUNT\tBALANCE\n CHECKER")
	print("press # is go back to the Main Menu.")
	pin=input("Enter your 4 digit pin:")
# isdigit( ) is used to  check for digits within a str while the nested if is used to make sure the user inputs 4 digits.

###```i am to put the pin trial in a while loop```###REMINDER!!!

	if len(pin)!=4:
	   	print("Make sure its a 4digit pin.")
	   	time.sleep(5)
	   	balance( )
	else:
	   		    if pin.isdigit( )==True:
	   		        time.sleep(5)
	   		        print("Loading...")
	   		        exit( )
	   		    elif pin== "#":
	   		        options_menu( )
	   		    else:
	   		        time.sleep(15)
	   		        print("wrong pin")
	   		        sys.exit( )
		
def transf( ):
	print("1. Transfer self\n2. Transfer others")
	print("press # is go back to the Main Menu.")
	trnsf=input(":")
	if trnsf == "#" :
	    options_menu( )
	elif trnsf == "1":
	    time.sleep(5)
	    print("Sending...")
	    exit( )
	elif trnsf=="2":
	    time.sleep(5)
	    num=int(input("Enter receivers mobile number:"))
	    print("Transferring to",num)
	    exit( )

Review comment (suggestion):
Compare True Statements(Don't write extra statement)
```suggestion
	   		    if pin.isdigit( ):

```

Code after:
		print("Welcome to our online Upgrade/Migration services.\n 1. Ugrade\n 2. Migrate")
		print("press # is go back to the Main Menu.")
		prompt = input("Enter preferred Choice:")
		if prompt=="1":
			time.sleep(5)
			print("Upgrading...")
			exit( )
		elif prompt == "2":
			time.sleep(5)
			print("Migrating...")
			exit( )
		elif prompt == "#":
			options_menu( )
		else:
			sys.exit( )

def balance ( ):
	print("ACCOUNT\tBALANCE\n CHECKER")
	print("press # is go back to the Main Menu.")
	pin=input("Enter your 4 digit pin:")
# isdigit( ) is used to  check for digits within a str while the nested if is used to make sure the user inputs 4 digits.

###```i am to put the pin trial in a while loop```###REMINDER!!!

	if len(pin)!=4:
	   	print("Make sure its a 4digit pin.")
	   	time.sleep(5)
	   	balance( )
	else:
	   		    if pin.isdigit( ):
	   		        time.sleep(5)
	   		        print("Loading...")
	   		        exit( )
	   		    elif pin== "#":
	   		        options_menu( )
	   		    else:
	   		        time.sleep(15)
	   		        print("wrong pin")
	   		        sys.exit( )
		
def transf( ):
	print("1. Transfer self\n2. Transfer others")
	print("press # is go back to the Main Menu.")
	trnsf=input(":")
	if trnsf == "#" :
	    options_menu( )
	elif trnsf == "1":
	    time.sleep(5)
	    print("Sending...")
	    exit( )
	elif trnsf=="2":
Repository: Python-World/python-mini-projects
File: projects/Unstructured Supplemenrary  Service Data/ussdtim.py (Python)

Code before:
4. Heritage Bank
5. Polaris Bank
6. Stanbic IBTC
7. Unity Bank
8. Wema Bank
"""

gen_bvn = " "

def BVN_checker( ):
    global gen_bvn
    bvn = [str(i) for i in range (5)]
    gen_bvn= "".join(bvn)
    print (gen_bvn)
       				
def open_acct( ):
	global gen_bvn
	print("Welcome to our online Account opening services.")
	print("loading...")
# creating an empty list to serve as a temporary place holder.
	temp_storage= [ ]
	f_name= input("Enter your first name:")
	s_name= input ("Enter your second name:")
	sex = input("Enter sex [M/F]:")
	BVN_checker( )
	temp_storage.append(f_name)
	temp_storage.append(s_name)
	temp_storage.append(sex)
	temp_storage.append(gen_bvn)
	details= " ".join(temp_storage)
	print(details)
	print("1. Press # to go back to options menu\n2. Press * to exit")
	bck=input(":")
	if bck=='#':
	    options_menu( )
	else:
	    sys.exit( )
	
	exit( )
	
def upgrade_migrate( ):
		print("Welcome to our online Upgrade/Migration services.\n 1. Ugrade\n 2. Migrate")
		print("press # is go back to the Main Menu.")
		prompt = int(input("Enter preferred Choice:"))
		if prompt==1:
			time.sleep(5)
			print("Upgrading...")
			exit( )
		elif prompt == 2:
			time.sleep(5)
			print("Migrating...")

Review comment (suggestion):
use Extend to insert multiple object
```suggestion
	temp_storage.extend([f_name,s_name,sex,gen_bvn])

```

Code after:
4. Heritage Bank
5. Polaris Bank
6. Stanbic IBTC
7. Unity Bank
8. Wema Bank
"""

gen_bvn = " "

def BVN_checker( ):
    global gen_bvn
    bvn = [str(i) for i in range (5)]
    gen_bvn= "".join(bvn)
    
       				
def open_acct( ):
	global gen_bvn
	print("Welcome to our online Account opening services.")
	print("loading...")
# creating an empty list to serve as a temporary place holder.
	temp_storage= [ ]
	f_name= input("Enter your first name:")
	s_name= input ("Enter your second name:")
	sex = input("Enter sex [M/F]:")
	BVN_checker( )
	temp_storage.append(f_name)
	temp_storage.append(s_name)
	temp_storage.append(sex)
	temp_storage.append(gen_bvn)
	details= " ".join(temp_storage)
	split_details = details.split(" ")
	#print(split_details)
	print(split_details[0]+" "+split_details[1])
	print(split_details[2])
	print("Your bvn is :"+split_details[3])
	print("1. Press # to go back to options menu\n2. Press * to exit")
	bck=input(":")
	if bck=='#':
	    options_menu( )
	else:
	    sys.exit( )
	
	exit( )
	
def upgrade_migrate( ):
		print("Welcome to our online Upgrade/Migration services.\n 1. Ugrade\n 2. Migrate")
		print("press # is go back to the Main Menu.")
		prompt = input("Enter preferred Choice:")
		if prompt=="1":
			time.sleep(5)
			print("Upgrading...")
Repository: Python-World/python-mini-projects
File: projects/Unstructured Supplemenrary  Service Data/ussdtim.py (Python)

Code before:
	print("1. Press # to go back to options menu\n2. Press * to exit")
	bck=input(":")
	if bck=='#':
	    options_menu( )
	else:
	    sys.exit( )
	
	exit( )
	
def upgrade_migrate( ):
		print("Welcome to our online Upgrade/Migration services.\n 1. Ugrade\n 2. Migrate")
		print("press # is go back to the Main Menu.")
		prompt = int(input("Enter preferred Choice:"))
		if prompt==1:
			time.sleep(5)
			print("Upgrading...")
			exit( )
		elif prompt == 2:
			time.sleep(5)
			print("Migrating...")
			exit( )
		elif prompt == "#":
			options_menu( )
		else:
			sys.exit( )

def balance ( ):
	print("ACCOUNT\tBALANCE\n CHECKER")
	print("press # is go back to the Main Menu.")
	pin=input("Enter your 4 digit pin:")
# isdigit( ) is used to  check for digits within a str while the nested if is used to make sure the user inputs 4 digits.

###```i am to put the pin trial in a while loop```###REMINDER!!!

	if len(pin)!=4:
	   	print("Make sure its a 4digit pin.")
	   	time.sleep(5)
	   	balance( )
	else:
	   		    if pin.isdigit( )==True:
	   		        time.sleep(5)
	   		        print("Loading...")
	   		        exit( )
	   		    elif pin== "#":
	   		        options_menu( )
	   		    else:
	   		        time.sleep(15)
	   		        print("wrong pin")
	   		        sys.exit( )
		
def transf( ):

Review comment (suggestion):
this statement never Executed because prompt is and int value 

(Compare variable and data with same data type)

Code after:
	#print(split_details)
	print(split_details[0]+" "+split_details[1])
	print(split_details[2])
	print("Your bvn is :"+split_details[3])
	print("1. Press # to go back to options menu\n2. Press * to exit")
	bck=input(":")
	if bck=='#':
	    options_menu( )
	else:
	    sys.exit( )
	
	exit( )
	
def upgrade_migrate( ):
		print("Welcome to our online Upgrade/Migration services.\n 1. Ugrade\n 2. Migrate")
		print("press # is go back to the Main Menu.")
		prompt = input("Enter preferred Choice:")
		if prompt=="1":
			time.sleep(5)
			print("Upgrading...")
			exit( )
		elif prompt == "2":
			time.sleep(5)
			print("Migrating...")
			exit( )
		elif prompt == "#":
			options_menu( )
		else:
			sys.exit( )

def balance ( ):
	print("ACCOUNT\tBALANCE\n CHECKER")
	print("press # is go back to the Main Menu.")
	pin=input("Enter your 4 digit pin:")
# isdigit( ) is used to  check for digits within a str while the nested if is used to make sure the user inputs 4 digits.

###```i am to put the pin trial in a while loop```###REMINDER!!!

	if len(pin)!=4:
	   	print("Make sure its a 4digit pin.")
	   	time.sleep(5)
	   	balance( )
	else:
	   		    if pin.isdigit( ):
	   		        time.sleep(5)
	   		        print("Loading...")
	   		        exit( )
	   		    elif pin== "#":
	   		        options_menu( )
	   		    else:
	   		        time.sleep(15)
Repository: Python-World/python-mini-projects
File: projects/Unstructured Supplemenrary  Service Data/ussdtim.py (Python)

Code before:
4. Heritage Bank
5. Polaris Bank
6. Stanbic IBTC
7. Unity Bank
8. Wema Bank
"""

gen_bvn = " "

def BVN_checker( ):
    global gen_bvn
    bvn = [str(i) for i in range (5)]
    gen_bvn= "".join(bvn)
    print (gen_bvn)
       				
def open_acct( ):
	global gen_bvn
	print("Welcome to our online Account opening services.")
	print("loading...")
# creating an empty list to serve as a temporary place holder.
	temp_storage= [ ]
	f_name= input("Enter your first name:")
	s_name= input ("Enter your second name:")
	sex = input("Enter sex [M/F]:")
	BVN_checker( )
	temp_storage.extend(f_name)
	temp_storage.extend(s_name)
	temp_storage.extend(sex)
	temp_storage.extend(gen_bvn)
	details= " ".join(temp_storage)
	print(details)
	print("1. Press # to go back to options menu\n2. Press * to exit")
	bck=input(":")
	if bck=='#':
	    options_menu( )
	else:
	    sys.exit( )
	
	exit( )
	
def upgrade_migrate( ):
		print("Welcome to our online Upgrade/Migration services.\n 1. Ugrade\n 2. Migrate")
		print("press # is go back to the Main Menu.")
		prompt = input("Enter preferred Choice:")
		if prompt=="1":
			time.sleep(5)
			print("Upgrading...")
			exit( )
		elif prompt == "2":
			time.sleep(5)
			print("Migrating...")

Review comment (suggestion):
it will convert your input to list and append to list
Example:
```python
temp_storage = []
f_name = "Roy"
temp_storage.extend(f_name)

# print temp_storage
print(temp_storage)

'''
["R","o","y"]
'''
```
correct it..

Code after:
4. Heritage Bank
5. Polaris Bank
6. Stanbic IBTC
7. Unity Bank
8. Wema Bank
"""

gen_bvn = " "

def BVN_checker( ):
    global gen_bvn
    bvn = [str(i) for i in range (5)]
    gen_bvn= "".join(bvn)
    
       				
def open_acct( ):
	global gen_bvn
	print("Welcome to our online Account opening services.")
	print("loading...")
# creating an empty list to serve as a temporary place holder.
	temp_storage= [ ]
	f_name= input("Enter your first name:")
	s_name= input ("Enter your second name:")
	sex = input("Enter sex [M/F]:")
	BVN_checker( )
	temp_storage.append(f_name)
	temp_storage.append(s_name)
	temp_storage.append(sex)
	temp_storage.append(gen_bvn)
	details= " ".join(temp_storage)
	split_details = details.split(" ")
	#print(split_details)
	print(split_details[0]+" "+split_details[1])
	print(split_details[2])
	print("Your bvn is :"+split_details[3])
	print("1. Press # to go back to options menu\n2. Press * to exit")
	bck=input(":")
	if bck=='#':
	    options_menu( )
	else:
	    sys.exit( )
	
	exit( )
	
def upgrade_migrate( ):
		print("Welcome to our online Upgrade/Migration services.\n 1. Ugrade\n 2. Migrate")
		print("press # is go back to the Main Menu.")
		prompt = input("Enter preferred Choice:")
		if prompt=="1":
			time.sleep(5)
			print("Upgrading...")
Repository: Python-World/python-mini-projects
File: projects/Scraping Medium Articles/scraping_medium.py (Python)

Code before:
import os
import sys
import requests
import re
from bs4 import BeautifulSoup

# switching to current running python files directory
os.chdir('\\'.join(__file__.split('/')[:-1]))

# function to get the html of the page
def get_page():
	url = input('Enter url of a medium article: ')
	# handling possible error
	if (url[:18] != 'https://medium.com') and (url[:17] != 'http://medium.com'):
		print('Please enter a valid website, or make sure it is a medium article')
		sys.exit(1)
	res = requests.get(url)
	res.raise_for_status()
	soup = BeautifulSoup(res.text, 'html.parser')
	return url, soup

# function to remove all the html tags and replace some with specific strings
def purify(text):
    rep = {"<br>": "\n", "<br/>": "\n", "<li>":  "\n"}
    rep = dict((re.escape(k), v) for k, v in rep.items()) 
    pattern = re.compile("|".join(rep.keys()))
    text = pattern.sub(lambda m: rep[re.escape(m.group(0))], text)
    text = re.sub('\<(.*?)\>', '', text)
    return text

# function to compile all of the scraped text in one string
def collect_text(url, soup):
	fin = f'url: {url}\n\n'
	main = (soup.head.title.text).split('|')
	fin += f'Title:   {main[0].strip().upper()}\n{main[1].strip()}'

	header = soup.find_all('h1')
	j = 1


Review comment (suggestion):
instead of if u can use regex pattern matching
```suggestion
	if not re.match(r'https?://medium.com/',url):
```

Code after:
import os
import sys
import requests
import re
from bs4 import BeautifulSoup

# switching to current running python files directory
os.chdir('\\'.join(__file__.split('/')[:-1]))

# function to get the html of the page
def get_page():
	global url
	url = input('Enter url of a medium article: ')
	# handling possible error
	if not re.match(r'https?://medium.com/',url):
		print('Please enter a valid website, or make sure it is a medium article')
		sys.exit(1)
	res = requests.get(url)
	res.raise_for_status()
	soup = BeautifulSoup(res.text, 'html.parser')
	return soup

# function to remove all the html tags and replace some with specific strings
def purify(text):
    rep = {"<br>": "\n", "<br/>": "\n", "<li>":  "\n"}
    rep = dict((re.escape(k), v) for k, v in rep.items()) 
    pattern = re.compile("|".join(rep.keys()))
    text = pattern.sub(lambda m: rep[re.escape(m.group(0))], text)
    text = re.sub('\<(.*?)\>', '', text)
    return text

# function to compile all of the scraped text in one string
def collect_text(soup):
	fin = f'url: {url}\n\n'
	main = (soup.head.title.text).split('|')
	global title
	title = main[0].strip()
	fin += f'Title: {title.upper()}\n{main[1].strip()}'