Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python project example

This depends on the type of project... 
But for this instance I will do a calculator:

import math
print("1.Addition")
print("2.Subtraction")
print("3.Multiplication")
print("4.Division")
print("5.Exponents")
print("6.Squareroot")
print()
user_choice = input('What choice?:  ')


if '1' in user_choice:
    first_digit = input('Enter first didgit:  ')
    second_digit = input('enter second digit:  ')
    
    #Setting addition
    end_result_of_addition = float(first_digit) + float(second_digit)
    
    #Addition
    print(end_result_of_addition)
    print()
    print('done')


if '2' in user_choice:
    first_digit = input('Enter first didgit:  ')
    second_digit = input('enter second digit:  ')
    
    #Setting subtraction
    end_result_of_subtraction = float(first_digit) - float(second_digit)
    
    #Subtraction
    print(end_result_of_subtraction)
    print('done')
    
if '3' in user_choice:
    first_digit = input('Enter first didgit:  ')
    second_digit = input('enter second digit:  ')
    
    #Setting multiplaction
    end_result_of_multiplication = float(first_digit) * float(second_digit)
    
    #Multiplication
    print(end_result_of_multiplication)
    print()
    print('done')

if '4' in user_choice:
    first_digit = input('Enter first didgit:  ')
    second_digit = input('enter second digit:  ')
    
    #Setting division
    end_result_of_division = float(first_digit) / float(second_digit)
    
    #Division
    print(end_result_of_division)
    print()
    print('done')
    
    
if '5' in user_choice:
    base = input('enter base:  ')
    exponent = input('enter exponent:  ')
    print()
    print("  ",exponent)
    print(base,"^")
    print()
    print('solving')
    print()
    #Setting exponents
    user_choice_of_exponent = float(base) ** int(exponent)
    print(user_choice_of_exponent)
    print()       
if '6' in user_choice:
    first_digit = input('what number?:  ')
    print()
    print(math.sqrt(float(first_digit)))
    print()
    print('done')
    print()
Source by itswachira.hashnode.dev #
 
PREVIOUS NEXT
Tagged: #python #project
ADD COMMENT
Topic
Name
1+7 =