Last active
April 28, 2021 15:05
-
-
Save Skydrifa/ec8d30ecf09b07effc624ed687597ec2 to your computer and use it in GitHub Desktop.
Golden Ratio & Fibonacci Sequence _ Calculator for Designers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Homework 8.3: Calculator of Golden Ratio & Fibonacci Sequence | |
pt = 0.75292857248934 | |
rem = 0.0625 | |
x = 1.618 | |
nterms = 10 | |
# Python program to display the Fibonacci sequence | |
def recur_fibo(n): | |
if n <= 1: | |
return n | |
else: | |
return(recur_fibo(n-1) + recur_fibo(n-2)) | |
# This function multiplies two numbers | |
def multiply(x, y): | |
return x * y | |
# This function divides two numbers | |
def divide(x, y): | |
return x / y | |
print("Choice 1 = Body px to Header px; Choice 2 = Header px to Body px; Choice 3 = px to rem; Choice 4 = px to pt; Choice 5 = Fibonacci sequence") | |
while True: | |
# Take input from the user | |
choice = input("Enter choice (1/2/3/4/5): ") #não pode ser int pois o input depois não é váçido para o choice ou seja o choice é uma string por natureza | |
# Check if choice is one of the four options | |
if choice in ('1', '2', '3', '4', '5'): | |
px = int(input("Enter first number: ")) | |
if choice == '1': | |
print((float(px, "*", x, "=", multiply(px, x)))) | |
elif choice == '2': | |
print((float(px, "/", x, "=", divide(px, x)))) | |
elif choice == '3': | |
print((float(px, "*", rem, "=", multiply(px, rem)))) | |
elif choice == '4': | |
print(float(px, "*", pt, "=", multiply(px, pt))) | |
elif choice == '5': | |
print(int(px)) | |
for i in range(px, nterms): | |
print(recur_fibo(i)) | |
break | |
else: | |
print("Invalid Input") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment