Skip to content

Instantly share code, notes, and snippets.

@BlueNexus
Last active April 21, 2024 23:25
Show Gist options
  • Save BlueNexus/599962d03a1b52a8d5f595dabd51dc34 to your computer and use it in GitHub Desktop.
Save BlueNexus/599962d03a1b52a8d5f595dabd51dc34 to your computer and use it in GitHub Desktop.
Python to Pseudocode converter
import os.path
import re
'''
INSTRUCTIONS
1. Create a file with the following code
2. Put the file you want to convert into the same folder as it, and rename it to "py_file.py"
3. Add a "#F" comment to any lines in the code which have a function call that doesn't assign anything (so no =),
as the program cannot handle these convincingly
4. Run the converter file
'''
python_file = 'py_file.py'
basic_conversion_rules = {"for": "FOR", "=": "TO", "if": "IF", "==": "EQUALS", "while": "WHILE", "until": "UNTIL",
"import": "IMPORT", "class": "DEFINE CLASS", "def": "DEFINE FUNCTION", "else:": "ELSE:",
"elif": "ELSEIF", "except:": "EXCEPT:", "try:": "TRY:", "pass": "PASS", "in": "IN"}
prefix_conversion_rules = {"=": "SET ", "#F": "CALL "}
advanced_conversion_rules = {"print": "OUTPUT", "return": "RETURN", "input": "INPUT"}
def l2pseudo(to_pseudo):
for line in to_pseudo:
line_index = to_pseudo.index(line)
line = str(line)
line = re.split(r'(\s+)', line)
for key, value in prefix_conversion_rules.items():
if key in line:
if not str(line[0]) == '':
line[0] = value + line[0]
else:
line[2] = value + line[2]
for key, value in basic_conversion_rules.items():
for word in line:
if key == str(word):
line[line.index(word)] = value
for key, value in advanced_conversion_rules.items():
for word in line:
line[line.index(word)] = word.replace(key, value)
for key, value in prefix_conversion_rules.items():
for word in line:
if word == key:
del line[line.index(word)]
to_pseudo[line_index] = "".join(line)
return to_pseudo
def p2file(to_file):
py_file = os.path.splitext(os.path.basename(python_file))[0]
with open(py_file + '_pseudo.txt', 'w') as writer:
writer.write("\n".join(to_file))
def main():
with open(python_file, 'r+') as py_file_reader:
file_lines = py_file_reader.readlines()
work_file = l2pseudo(file_lines)
p2file(work_file)
if __name__ == '__main__':
main()
@BlueNexus
Copy link
Author

Might want to add the encoding="utf8" parameter when calling open() since I was getting this error:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 867: character maps to <undefined>

I found adding the encoding parameter resolved the issue

Good idea, thanks

@mentain
Copy link

mentain commented Sep 1, 2022

please I need help converting this code to pseudocode.

def find_repeat(S):
length = len(S)
array_check = [0]*(length)
for element in S:
if array_check[element]: return element
else: array_check[element] = 1

return ('No duplicate found in Array')

S = [1,2,2,3,4,5,6]
print("Repeated value =",find_repeat(S))

output is given as: Repeated value= 2

@meryemebekka
Copy link

Could you pls help? thx!

student_number=0
formclass=""
classlist=[]
form=[]
form_teacher=[]

student_number=int(input("Enter number of students: "))
print("You have entered ",student_number)

for i in range (0,student_number):
classlist.append(input("Enter student name: "))
formclass=input("Enter your form class (11A,11B,11C): ")

if formclass =="11A":
form.append(formclass)
form_teacher.append("Mr Jackson")

elif formclass =="11B":
form.append(formclass)
form_teacher.append("Mr Ziad")

elif formclass =="11C":
form.append(formclass)
form_teacher.append("Dr Mohammed")

else:
print("You did not enter a valid form.")
form.append("Invalid")

for i in range (0,student_number):
print("-----------------------------------------------")
print("Name: ",classlist[i])
print("Form: ",form[i])
print("Form Teacher: ",form_teacher[i])
print("-----------------------------------------------")

@dagabate
Copy link

Hello, what about to convert the pseudocode into python code?
Thanks

@Malr21
Copy link

Malr21 commented Oct 1, 2022

im confused about how to run it

@Malr21
Copy link

Malr21 commented Oct 1, 2022

@BlueNexus

i have download the file and added the code i want now how do i run it

@taasvin
Copy link

taasvin commented Oct 12, 2022

Hi i AM PHYTON BEGINNER. TEACHER GIVE ME ASSIGNMENT TO COMPLETE BEFORE 30 OCTOBOR.
PLS HELP CHANGE THIS CODE TO PSEUDOCODE

def print_menu():
print('1. Celcius to Farenheit')
print('2. Farenheit to Celcius')
print('3. kilogram to pound')
print('4. pound to kilogram')
print('5. cm to inch')
print('6. inch to cm')

def celcius_farenheit():
celcius = float(input('Enter a temperature in celcius:'))
farenheit = (9/5 * celcius)+32
print('In farenheit:',format(farenheit))

def farenheit_celcius():
farenheit = float(input('Enter a temperature in farenheit: '))
celcius = (farenheit - 32) * 5/9
print ('celcius temperature: ', format(celcius))

def kilogram_pound():
kilogram = float(input('Enter a weight in kilogram:'))
pound = (kilogram * 2.205)
print('In pound:',format(pound))

def pound_kilogram():
pound = float(input('Enter a weight in pound: '))
kilogram = (pound/2.205)
print (' In kilogram:',format(kilogram))

def cm_inch():
cm = float(input('Enter a length in cm:'))
inch = (cm / 2.54)
print('In inch:',format(inch))

def inch_cm():
inch = float(input('Enter a length in inch: '))
cm = (inch * 2.54)
print (' In cm:',format(cm))

print_menu()

choice = input('Which conversion would you like to do?: ')

if choice =='1':
celcius_farenheit()
if choice =='2':
farenheit_celcius()
if choice =='3':
kilogram_pound()
if choice =='4':
pound_kilogram()
if choice =='5':
cm_inch()
if choice =='6':
inch_cm()

@effaaaaaaa
Copy link

Pls help me convert java to pseudocode

import java.util.Scanner;
public class Question2 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//input from the user
System.out.print("Enter integer : ");
int num = sc.nextInt();
System.out.println("Sum of Digits(without using recursion): " + add(num));
System.out.println("Sum of Digits(using recursion):" +
add_rec(num));
}
static int add(int num)
{
int sum = 0;
while(num !=0)
{
sum = sum + (num % 10);
num = num / 10;
}
return(sum);
}
static int add_rec(int num)
{
if(num != 0)
{
return((num % 10) + add_rec(num / 10) );
}
else
{
return 0;
}
}
}

@BlueNexus
Copy link
Author

Pls help me convert java to pseudocode

import java.util.Scanner; public class Question2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //input from the user System.out.print("Enter integer : "); int num = sc.nextInt(); System.out.println("Sum of Digits(without using recursion): " + add(num)); System.out.println("Sum of Digits(using recursion):" + add_rec(num)); } static int add(int num) { int sum = 0; while(num !=0) { sum = sum + (num % 10); num = num / 10; } return(sum); } static int add_rec(int num) { if(num != 0) { return((num % 10) + add_rec(num / 10) ); } else { return 0; } } }

This is a python pseudocode tool, I can't help with Java.

@luckyillama
Copy link

pls help me convert python to pseudocode

SUB_HEIGHT = 3

def main():
drawLine1()
drawCactus1()
drawLine2()
drawCactus2()
drawLine3()
drawCactus3()

def drawLine1():
for count in range(1):
print(" ", end='')
for count in range(1, SUB_HEIGHT + 1 , 1):
print("x", end='')
for count in range(SUB_HEIGHT+1):
print(" ", end='')
for count in range(1, 2 * SUB_HEIGHT):
print("x", end='')
print("x")

def drawCactus1():
for line in range(1, 2 * SUB_HEIGHT, 1):
for count in range(1):
print("X", end='')
for count in range(1, SUB_HEIGHT + 1 , 1):
print("-", end='')
for count in range(1):
print("X", end='')
for count in range(SUB_HEIGHT-1):
print(" ", end='')
for count in range(1):
print("X", end='')
for count in range(1, line + 1, 1):
print("/", end='')
for count in range(1, 2 * SUB_HEIGHT - 1 * line + 1, 1):
print("-", end='')
for count in range(1):
print("X", end='')
print()

def drawLine2():
for count in range(1):
print(" ", end='')
for count in range(1, 2 * SUB_HEIGHT + 1, 1):
print("x", end='')
for count in range(1):
print("X", end='')
for count in range(1, 2 * SUB_HEIGHT + 1, 1):
print("~", end='')
for count in range(1):
print("X", end='')
for count in range(SUB_HEIGHT):
print(" ", end='')
for count in range(1, SUB_HEIGHT + 1 , 1):
print("x", end='')
print()

def drawCactus2():
for line in range(1,2 * SUB_HEIGHT, 1):
for count in range(1, 2 * SUB_HEIGHT + 2, 1):
print(" ", end='')
for count in range(1):
print("X", end='')
for count in range(1, 2 * SUB_HEIGHT-1 * line + 1, 1):
print("-", end='')
for count in range(1, line + 1, 1):
print("\", end='')
for count in range(1):
print("X", end='')
for count in range(SUB_HEIGHT-1):
print(" ", end='')
for count in range(1):
print("X", end='')
for count in range(1, SUB_HEIGHT + 1 , 1):
print("-", end='')
for count in range(1):
print("X", end='')
print()

def drawLine3():
for count in range(1, 2* SUB_HEIGHT+2, 1):
print(" ", end='')
for count in range(1):
print("X", end='')
for count in range(1, 2 * SUB_HEIGHT + 1, 1):
print("~", end='')
for count in range(1):
print("X", end='')
for count in range(1, 2 * SUB_HEIGHT + 1, 1):
print("x", end='')
print()

def drawCactus3():
for line in range(2 * SUB_HEIGHT):
for count in range(1, 2 * SUB_HEIGHT + 2, 1):
print(" ", end='')
for count in range(1):
print("X", end='')
for count in range(1, 2 * SUB_HEIGHT + 1, 1):
print("~", end='')
for count in range(1):
print("X", end='')
print()

main()

@BlueNexus
Copy link
Author

pls help me convert python to pseudocode

SUB_HEIGHT = 3

def main(): drawLine1() drawCactus1() drawLine2() drawCactus2() drawLine3() drawCactus3()

def drawLine1(): for count in range(1): print(" ", end='') for count in range(1, SUB_HEIGHT + 1 , 1): print("x", end='') for count in range(SUB_HEIGHT+1): print(" ", end='') for count in range(1, 2 * SUB_HEIGHT): print("x", end='') print("x")

def drawCactus1(): for line in range(1, 2 * SUB_HEIGHT, 1): for count in range(1): print("X", end='') for count in range(1, SUB_HEIGHT + 1 , 1): print("-", end='') for count in range(1): print("X", end='') for count in range(SUB_HEIGHT-1): print(" ", end='') for count in range(1): print("X", end='') for count in range(1, line + 1, 1): print("/", end='') for count in range(1, 2 * SUB_HEIGHT - 1 * line + 1, 1): print("-", end='') for count in range(1): print("X", end='') print()

def drawLine2(): for count in range(1): print(" ", end='') for count in range(1, 2 * SUB_HEIGHT + 1, 1): print("x", end='') for count in range(1): print("X", end='') for count in range(1, 2 * SUB_HEIGHT + 1, 1): print("~", end='') for count in range(1): print("X", end='') for count in range(SUB_HEIGHT): print(" ", end='') for count in range(1, SUB_HEIGHT + 1 , 1): print("x", end='') print()

def drawCactus2(): for line in range(1,2 * SUB_HEIGHT, 1): for count in range(1, 2 * SUB_HEIGHT + 2, 1): print(" ", end='') for count in range(1): print("X", end='') for count in range(1, 2 * SUB_HEIGHT-1 * line + 1, 1): print("-", end='') for count in range(1, line + 1, 1): print("", end='') for count in range(1): print("X", end='') for count in range(SUB_HEIGHT-1): print(" ", end='') for count in range(1): print("X", end='') for count in range(1, SUB_HEIGHT + 1 , 1): print("-", end='') for count in range(1): print("X", end='') print()

def drawLine3(): for count in range(1, 2* SUB_HEIGHT+2, 1): print(" ", end='') for count in range(1): print("X", end='') for count in range(1, 2 * SUB_HEIGHT + 1, 1): print("~", end='') for count in range(1): print("X", end='') for count in range(1, 2 * SUB_HEIGHT + 1, 1): print("x", end='') print()

def drawCactus3(): for line in range(2 * SUB_HEIGHT): for count in range(1, 2 * SUB_HEIGHT + 2, 1): print(" ", end='') for count in range(1): print("X", end='') for count in range(1, 2 * SUB_HEIGHT + 1, 1): print("~", end='') for count in range(1): print("X", end='') print()

main()

Are you having problems while trying to follow the instructions in the gist?

@ddadum05
Copy link

please someone convert this into a pseudocode

#Program to create strong password generator
import random
uppercase_letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lowercase_letters= uppercase_letters.lower()
digits="0123456789"
symbols="!#$%&'()*+,-./:;<=>?@[]^_{}~"
#Booleans for selecting characters
upper,lower,nums,syms = True,True,True,True
#creating an empty string
all_chars=""
#Combining all characters
if upper:
all_chars += uppercase_letters
if lower:
all_chars += lowercase_letters
if nums:
all_chars += digits
if syms:
all_chars += symbols
#length of the password
length = 18
#amount of passwords
amount = 1
#generating password
for x in range(amount):
password ="".join(random.sample(all_chars,length))
print("Here is your password:",password)

@ZaahiFR
Copy link

ZaahiFR commented Feb 28, 2023

Prompt admin to input salary cycle date range

salary_cycle_begin_date = input("Enter salary cycle begin date (YYYY-MM-DD): ")
salary_cycle_end_date = input("Enter salary cycle end date (YYYY-MM-DD): ")

Verify if entered date range is valid

from datetime import datetime
try:
begin_date_obj = datetime.strptime(salary_cycle_begin_date, "%Y-%m-%d")
end_date_obj = datetime.strptime(salary_cycle_end_date, "%Y-%m-%d")
if end_date_obj < begin_date_obj:
raise ValueError
except ValueError:
print("Invalid date range entered. Please enter valid date range.")
exit()

Prompt admin to enter leave, absent days, holidays, overtime hours for employees

no_of_leaves = int(input("Enter number of leaves taken by employee: "))
no_of_absent_days = int(input("Enter number of absent days of employee: "))
no_of_holidays = int(input("Enter number of holidays for employee: "))
no_of_overtime_hours = int(input("Enter number of overtime hours worked by employee: "))

Calculate no-pay value if employee has any absent days

no_pay_value = 0
if no_of_absent_days > 0:
total_salary = get_employee_total_salary()
no_pay_value = (total_salary / (end_date_obj - begin_date_obj).days) * no_of_absent_days

Calculate base pay value

monthly_salary = get_employee_monthly_salary()
allowances = get_employee_allowances()
overtime_rate = get_employee_overtime_rate()
base_pay_value = monthly_salary + allowances + (overtime_rate * no_of_overtime_hours)

Calculate gross pay value

government_tax_rate = get_government_tax_rate()
gross_pay_value = base_pay_value - (no_pay_value + (base_pay_value * government_tax_rate))

Save the calculated values to database

save_employee_salary(salary_cycle_begin_date, salary_cycle_end_date, no_pay_value, base_pay_value, gross_pay_value)

Generate reports

generate_employee_monthly_salary_report()
generate_overall_salary_summary_report()
generate_no_pay_value_report()
generate_base_pay_value_report()
generate_gross_pay_value_report()

Can anyone convert this to pseudo code?

@BlueNexus
Copy link
Author

Please stop asking me to convert things to pseudocode. Use the tool provided in the gist.

@BlueNexus
Copy link
Author

Updated the tool with some better code that was provided to me

@BlueNexus
Copy link
Author

BlueNexus commented Feb 28, 2023

Credit to @Tuhin-thinks. Sorry for taking so long to add it.

@oVERTIME-tech
Copy link

oVERTIME-tech commented Mar 2, 2023

Can you guys help me. This is a C++ Code
Convert this code into pseudocode
#include
using namespace std;
int main()
{
int arrOne[50], arrTwo[50], arrMerge[100];
int sizeOne, sizeTwo, i, k;
cout<<"Enter the Size for First Array: ";
cin>>sizeOne;
cout<<"Enter "<<sizeOne<<" Elements for First Array: ";
for(i=0; i<sizeOne; i++)
{
cin>>arrOne[i];
arrMerge[i] = arrOne[i];
}
k = i;
cout<<"\nEnter the Size for Second Array: ";
cin>>sizeTwo;
cout<<"Enter "<<sizeTwo<<" Elements for Second Array: ";
for(i=0; i<sizeTwo; i++)
{
cin>>arrTwo[i];
arrMerge[k] = arrTwo[i];
k++;
}
cout<<"\nThe New Array (Merged Array):\n";
for(i=0; i<k; i++)
cout<<arrMerge[i]<<" ";
cout<<endl;
return 0;
}

@YaboiSalmon
Copy link

When i run it on python 3.10 it goes onto terminal for a split second then disappears. is that whats supposed to happen?

@BlueNexus
Copy link
Author

When i run it on python 3.10 it goes onto terminal for a split second then disappears. is that whats supposed to happen?

Yeah, that's intended, don't worry

@g7775
Copy link

g7775 commented Mar 26, 2023

#For BIR tax computation
#Input
print("Good day!")
A = float(input(" Employee's Monthly compensation: "))

#Conditions and Processes
if A < 20834:
BIR = 0
elif A > 20833 and A < 33333:
BIR = A * 0.15
elif A > 33332 and A < 66667:
BIR = (A * 0.20) + 1875
elif A > 66666 and A < 166667:
BIR = (A * 0.25) + 8541.80
elif A > 166666 and A < 666667:
BIR = (A * 0.30) + 33541.80
else:
BIR = (A * 0.35) + 183541.80

#Output
print("Your withholding tax is equal to Php", BIR)

#For SSS/GSIS contribution
#Process
SSSGSIS = A * 0.045

#Output
print("Your SSS/GSIS contribution is equal to Php", SSSGSIS)

#For Philhealth contribution
#Process
Philhealth = A * 0.02

#Output
print("Your Philhealth contribution is equal to Php", Philhealth)

#For Pag-IBIG contribution
#Conditions and Processes
if A < 1000:
PagIBIG = 0
elif A >= 1000 and A < 1500:
PagIBIG = A * 0.01
elif A >= 1500 and A < 5000:
PagIBIG = A * 0.02
else:
PagIBIG = A * 0.03

#Output
print("Your Pag-IBIG contribution is equal to Php", PagIBIG)

#Employee's total contribution and tax
#Process
X = BIR + SSSGSIS + Philhealth + PagIBIG

#Output
print("The total contribution and tax of your monthly Salary is equal to Php", X)

#Employee's Net Pay
#Process
NetPay = A - X

#Output
print("Your Net Pay is equal to Php", NetPay)
print("Thank You!")

@g7775
Copy link

g7775 commented Mar 26, 2023

#For BIR tax computation
#Input
print("Good day!")
A = float(input(" Employee's Monthly compensation: "))

#Conditions and Processes
if A < 20834:
BIR = 0
elif A > 20833 and A < 33333:
BIR = A * 0.15
elif A > 33332 and A < 66667:
BIR = (A * 0.20) + 1875
elif A > 66666 and A < 166667:
BIR = (A * 0.25) + 8541.80
elif A > 166666 and A < 666667:
BIR = (A * 0.30) + 33541.80
else:
BIR = (A * 0.35) + 183541.80

#Output
print("Your withholding tax is equal to Php", BIR)

#For SSS/GSIS contribution
#Process
SSSGSIS = A * 0.045

#Output
print("Your SSS/GSIS contribution is equal to Php", SSSGSIS)

#For Philhealth contribution
#Process
Philhealth = A * 0.02

#Output
print("Your Philhealth contribution is equal to Php", Philhealth)

#For Pag-IBIG contribution
#Conditions and Processes
if A < 1000:
PagIBIG = 0
elif A >= 1000 and A < 1500:
PagIBIG = A * 0.01
elif A >= 1500 and A < 5000:
PagIBIG = A * 0.02
else:
PagIBIG = A * 0.03

#Output
print("Your Pag-IBIG contribution is equal to Php", PagIBIG)

#Employee's total contribution and tax
#Process
X = BIR + SSSGSIS + Philhealth + PagIBIG

#Output
print("The total contribution and tax of your monthly Salary is equal to Php", X)

#Employee's Net Pay
#Process
NetPay = A - X

#Output
print("Your Net Pay is equal to Php", NetPay)
print("Thank You!")

@Tuhin-thinks
Copy link

@BlueNexus Awesome!! Good to see you have added it!

@parshvibid
Copy link

import os

File to store the readings

file_path = "bp_readings.txt"

Function to record a new blood pressure reading

def record_reading(upper, lower):
with open(file_path, 'a') as file:
file.write(f"{upper},{lower}\n")

Function to calculate the current average of all readings

def calculate_average():
if not os.path.exists(file_path):
return None, None

with open(file_path, 'r') as file:
    lines = file.readlines()
    if not lines:
        return None, None
    
    total_upper, total_lower = 0, 0
    for line in lines:
      values = line.strip().split(",")
if len(values)>= 2:
    upper,lower=map(int,values)
    total_upper += upper
    total_lower += lower
    
    avg_upper = total_upper / len(lines)
    avg_lower = total_lower / len(lines)
    return avg_upper, avg_lower

calculate_average()

Function to display all readings recorded so far

def display_readings():
readings = []
if not os.path.exists(file_path):
return readings

with open(file_path, 'r') as file:
    lines = file.readlines()
    for line in lines:
        upper, lower=map(int,line.strip().split(","))
        readings.append((upper, lower))
return readings

display_readings()

def main_interface():
while True:
print("\nBlood Pressure Recorder")
print("1. Record a new blood pressure reading")
print("2. Calculate the current average of all readings")
print("3. See all the readings recorded so far")
print("4. Exit")

    choice = input("Enter your choice (1/2/3/4): ")
    
    if choice == "1":
        upper = int(input("Enter the upper number: "))
        lower = int(input("Enter the lower number: "))
        record_reading(upper, lower)
        print("Reading recorded successfully!")
    
    elif choice == "2":
        avg_upper, avg_lower = calculate_average()
        if avg_upper is None:
            print("No readings found!")
        else:
            print(f"Average Upper Reading: {avg_upper:.2f}")
            print(f"Average Lower Reading: {avg_lower:.2f}")
    
    elif choice == "3":
        readings = display_readings()
        if not readings:
            print("No readings found!")
        else:
            print("\nRecorded Readings:")
            for upper, lower in readings:
                print(f"Upper: {upper}, Lower: {lower}")
    
    elif choice == "4":
        print("Goodbye!")
        break
    
    else:
        print("Invalid choice! Please select a valid option.")

Let's run the interface to see how it works

For the sake of this platform, we'll not execute the infinite loop here, but the code provided will work outside.

Uncomment the line below to run the interface:

main_interface()

can u pls convert this to pseudocode

@BlueNexus
Copy link
Author

import os

File to store the readings

file_path = "bp_readings.txt"

Function to record a new blood pressure reading

def record_reading(upper, lower): with open(file_path, 'a') as file: file.write(f"{upper},{lower}\n")

Function to calculate the current average of all readings

def calculate_average(): if not os.path.exists(file_path): return None, None

with open(file_path, 'r') as file:
    lines = file.readlines()
    if not lines:
        return None, None
    
    total_upper, total_lower = 0, 0
    for line in lines:
      values = line.strip().split(",")
if len(values)>= 2:
    upper,lower=map(int,values)
    total_upper += upper
    total_lower += lower
    
    avg_upper = total_upper / len(lines)
    avg_lower = total_lower / len(lines)
    return avg_upper, avg_lower

calculate_average()

Function to display all readings recorded so far

def display_readings(): readings = [] if not os.path.exists(file_path): return readings

with open(file_path, 'r') as file:
    lines = file.readlines()
    for line in lines:
        upper, lower=map(int,line.strip().split(","))
        readings.append((upper, lower))
return readings

display_readings()

def main_interface(): while True: print("\nBlood Pressure Recorder") print("1. Record a new blood pressure reading") print("2. Calculate the current average of all readings") print("3. See all the readings recorded so far") print("4. Exit")

    choice = input("Enter your choice (1/2/3/4): ")
    
    if choice == "1":
        upper = int(input("Enter the upper number: "))
        lower = int(input("Enter the lower number: "))
        record_reading(upper, lower)
        print("Reading recorded successfully!")
    
    elif choice == "2":
        avg_upper, avg_lower = calculate_average()
        if avg_upper is None:
            print("No readings found!")
        else:
            print(f"Average Upper Reading: {avg_upper:.2f}")
            print(f"Average Lower Reading: {avg_lower:.2f}")
    
    elif choice == "3":
        readings = display_readings()
        if not readings:
            print("No readings found!")
        else:
            print("\nRecorded Readings:")
            for upper, lower in readings:
                print(f"Upper: {upper}, Lower: {lower}")
    
    elif choice == "4":
        print("Goodbye!")
        break
    
    else:
        print("Invalid choice! Please select a valid option.")

Let's run the interface to see how it works

For the sake of this platform, we'll not execute the infinite loop here, but the code provided will work outside.

Uncomment the line below to run the interface:

main_interface()

can u pls convert this to pseudocode

Are you unable to run the tool in the gist? There are instructions at the top.

@parshvibid
Copy link

where

@BlueNexus
Copy link
Author

where

Copy the code from the top of this page into a .py file, and perform the following instructions:

  1. Create a file with the provided code
  2. Put the file you want to convert into the same folder as it, and rename it to "py_file.py"
  3. Add a "#F" comment to the end of any lines in the code which have a function call that doesn't assign anything (so no =),
    as the program cannot handle these convincingly
  4. Run the converter file

@sALkaldy
Copy link

Please can u help me to convert this cod into pseudcode

def printNGE(arr):
#prepare stack
s = list()
n = len(arr)
arr1 = [0 for i in range(n)]

for i in range(n - 1, -1, -1): 
	while (len(s) > 0 and s[-1] <= arr[i]:
		s.pop()
	if (len(s) == 0):
		arr1[i] = arr[i]	
	else:
		arr1[i] = s[-1]+arr[i]	 
	s.append(arr[i])

print(arr1)

arr = [7,4,5,10,2,1,7,8,2]
n = len(arr)
printNGE(arr)

@Echowe
Copy link

Echowe commented Jan 8, 2024

help me convert to pseudocode please

@Echowe
Copy link

Echowe commented Jan 8, 2024

def check_num_length(list,minimum):
count=0
for i in list:
if i.isdigit():
count += 1
if count>1 and len(list)>=minimum:
return True
else:
return False

def check_uppercase(list):
upper_count=0
for e in list:
if e.isupper():
upper_count+= 1
if upper_count>2:
return True
else:
return False

def check_lowercase(list):
lower_count=0
for o in list:
if o.islower():
lower_count+=1
if lower_count>2:
return True
else:
return False
minim=int(input("Minimum letters required?(has to be over 9)"))
while True:
lst=[]
txt=(input("Password?"))
for t in txt:
lst.append(t)
if check_num_length(lst,minim)==True and check_uppercase(lst)==True and check_lowercase(lst)==True:
print("Strong password")
break
else:
print("Weak password try again, the criterias are uppercase letters>2 lowercase letters>2 numbers>2 and the minimum length should be", minim)

@bsacm
Copy link

bsacm commented Mar 23, 2024

0_0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment