#08 Edabit Challanges

Go Back

Very easy

Return the Sum of Two Numbers

Brief: Create a function that takes two numbers as arguments and returns their sum.

def num(): num_1=int(input('Enter the first number: ')) num_2=int(input('Enter the second number: ')) return num_1,num_2 def calc(num_1,num_2): print('Number 1 + number 2 equals =',num_1+num_2) def_num_1,def_num_2=num() calc(def_num_1,def_num_2)

Return the Next Number from the Integer Passed

Brief: Create a function that takes a number as an argument, add one to the number, and return the result.

def num(): num_1=int(input('Enter the number: ')) return num_1 def calc(num_1): print('The number + 1 is',num_1+1) def_num_1=num() calc(def_num_1)

Convert Minutes into Seconds

Brief: Write a function that takes an integer minutes and converts it to seconds.

def num(): mins=int(input('Enter the amount of minutes: ')) return mins def calc(mins): print('The amount of seconds is is',mins*60) def_mins=num() calc(def_mins)

Area of a Triangle

Brief: Write a function that takes the base and height of a triangle and return its area.

def num(): base=int(input('Enter the base of the circle: ')) height=int(input('Enter the height of the circle: ')) return base,height def calc(base,height): print('The area of the triangle is',(base*height)/2) def_base,def_height=num() calc(def_base,def_height)

Convert Hours into Seconds

Brief: Write a function that converts hours into seconds.

def num(): hours=int(input('Enter the amount of hours: ')) return hours def calc(hours): print('The amount of hours in seconds is ',(hours*60)*60) def_hours=num() calc(def_hours)

Maximum Edge of a Triangle

Brief: Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers.

def num(): side_1=int(input('Enter the first side length: ')) side_2=int(input('Enter the second side length: ')) return side_1,side_2 def calc(side_1,side_2): print('The maximum range of the triangles third angle is ',(side_1+side_2)-1) def_side_1,def_side_2=num() calc(def_side_1,def_side_2)

Return the Remainder from Two Numbers

Brief: There is a single operator in Python, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value.

def num(): num_1=int(input('Enter the first number: ')) num_2=int(input('Enter the second number: ')) return num_1,num_2 def calc(num_1,num_2): print('The remainder of the two numbers are ',num_1%num_2) def_num_1,def_num_2=num() calc(def_num_1,def_num_2)

Return a String as an Integer

Brief: Create a function that takes a string and returns it as an integer.

def num(): num_1=str(input('Enter the number: ')) print(type(num_1)) return num_1 def calc(num_1): print('Changing type') print(type(int(num_1))) def_num_1=num() calc(def_num_1)

Convert Age to Days

Brief: Create a function that takes the age in years and returns the age in days.

def num(): age=int(input('Enter your age: ')) return age def calc(age): print('Your age in days is',age*365) def_age=num() calc(def_age)

Find the Perimeter of a Rectangle

Brief: Create a function that takes length and width and finds the perimeter of a rectangle.

def num(): length=int(input('Enter the length: ')) width=int(input('Enter the width: ')) return length,width def calc(length,width): print('The perimeter of the rectangle is',(length+width)*2) def_length,def_width=num() calc(def_length,def_width)

Power Calculator

Brief: Create a function that takes voltage and current and returns the calculated power.

def num(): voltage=int(input('Enter the voltage: ')) current=int(input('Enter the current: ')) return voltage,current def calc(voltage,current): print('the calculated power is ',voltage*current) def_voltage,def_current=num() calc(def_voltage,def_current)

Sum of Polygon Angles

Brief: Given an n-sided regular polygon n, return the total sum of internal angles (in degrees).

def num(): poly=int(input('Enter the poly: ')) return poly def calc(poly): print('The total sum of internal angles is ',(poly-2)*180) def_poly=num() calc(def_poly)

To the Power of _____

Brief: Create a function that takes a base number and an exponent number and returns the calculation.

def num(): num_1=int(input('Enter the base number: ')) power=int(input('Enter the number you want to power it by: ')) return num_1,power def calc(num_1,power): print('The number powered by the power is ',num_1**power) def_num_1,def_power=num() calc(def_num_1,def_power)

Boolean to String Conversion

Brief: Create a function that takes a boolean variable flag and returns it as a string.

def num(): str_1=bool(input('Enter the bool: ')) print(type(str_1)) return str_1 def calc(str_1): print('Changing type') print(type(str(str_1))) def_str_1=num() calc(def_str_1)

Return the First Element in a List

Brief: Create a function that takes a list containing only numbers and return the first element.

def num(): numbs=[346346,123123124,654547457,3414123,474574,52352342134,9789789789,32] return numbs def calc(numbs): print('the first element is',numbs[0]) def_numbs=num() calc(def_numbs)

Football Points

Create a function that takes the number of wins, draws and losses and calculates the number of points a football team has obtained so far.

def input_result(): wins=int(input("Enter the amount of wins you got this season: ")) draws=int(input("Enter the amount of draws you got this season: ")) losses=int(input("Enter the amount of losses you got this season: ")) return wins,draws def points_calc(wins,draws): wins_points=int(wins*3) draws_points=int(draws*1) print("You received",wins_points+draws_points,"points this season") def_wins,def_draws=input_result() points_calc(def_wins,def_draws)

The Farm Problem

Brief: In this challenge, a farmer is asking you to tell him how many legs can be counted among all his animals. The farmer breeds three species:

The farmer has counted his animals and he gives you a subtotal for each species. You have to implement a function that returns the total number of legs of all the animals.

def num(): chickens=int(input('Enter the amount of chickens you have: ')) cows=int(input('Enter the amount of cows you have: ')) pigs=int(input('Enter the amount of pigs you have: ')) return chickens,cows,pigs def calc(chickens,cows,pigs): print('The amount of legs on your farm is: ',(chickens*2)+(cows*4)+(pigs*4)) def_chickens,def_cows,def_pigs=num() calc(def_chickens,def_cows,def_pigs)

Easy

Stuttering Function

Brief: Write a function that stutters a word as if someone is struggling to read it. The first two letters are repeated twice with an ellipsis ... and space after each, and then the word is pronounced with a question mark ?.

def num(): word=str(input('Enter the word to stutter: ')) return word def calc(word): print(word[:2],'...',word[:2],'...',word,'?') def_word=num() calc(def_word)

Find the Discount

Brief: Create a function that takes two arguments: the original price and the discount percentage as integers and returns the final price after the discount.

def num(): num_1=int(input('Enter the origianl price: ')) num_2=int(input('Enter the discount percentage: ')) return num_1,num_2 def calc(num_1,num_2): print('With the applied discount the final price is',num_1-((num_2/100)*num_1)) def_num_1,def_num_2=num() calc(def_num_1,def_num_2)

Radians to Degrees

Brief: Create a function that takes an angle in radians and returns the corresponding angle in degrees rounded to one decimal place.

from math import pi def num(): num_1=float(input('Enter the angle is radians: ')) return num_1 def calc(num_1): print('The calculation of radians to degrees is ',round(num_1*(180/pi),2)) def_num_1=num() calc(def_num_1)

Circle or Square

Brief: Given the radius of a circle and the area of a square, return True if the circumference of the circle is greater than the square's perimeter and False if the square's perimeter is greater than the circumference of the circle.

import math as m def num(): num_1=float(input('Enter the radius of a circle: ')) num_2=float(input('Enter the area of a square: ')) return num_1,num_2 def calc(num_1,num_2): circumference=2*m.pi*num_1 perimeter=m.sqrt(num_2)*4 if circumference > perimeter: print('True') elif circumference < perimeter: print('False') else: print('Neither') def_num_1,def_num_2=num() calc(def_num_1,def_num_2)

Curzon Numbers

Brief: In this challenge, establish if a given integer num is a Curzon number. If 1 plus 2 elevated to num is exactly divisible by 1 plus 2 multiplied by num, then num is a Curzon number. Given a non-negative integer num, implement a function that returns True if num is a Curzon number, or False otherwise.

import math as m def num(): num=int(input('Enter a number to check if it is a curzon number: ')) return num def calc(num): power=pow(2,num)+1 times=2*num+1 if power%times==0: print('True') else: print('False') def_num=num() calc(def_num)

Luke, I Am Your ...

Brief: Luke Skywalker has family and friends. Help him remind them who is who. Given a string with a name, return the relation of that person to Luke.

Person Relation
Darth Vader Father
Leia Sister
Han Brother in law
R2D2 Droid

def name(): name=str(input('What is your name? ')) return name def calc(name): dict={ 'Darth Vader':'father', 'Leia':'sister', 'Han':'brother in law', 'R2D2':'droid' } print('Luke, I am your '+dict[name]+'.') def_name=num() calc(def_name)

Sum of Resistance in Series Circuits

Brief: When resistors are connected together in series, the same current passes through each resistor in the chain and the total resistance, RT, of the circuit must be equal to the sum of all the individual resistors added together. That is:

RT = R1 + R2 + R3 ...
Create a function that takes an array of values resistance that are connected in series, and calculates the total resistance of the circuit in ohms. The ohm is the standard unit of electrical resistance in the International System of Units ( SI ).

def num(): resistance=[] resistors=int(input('How many resistors are connected in the series: ')) for x in range(resistors): resistance.append(float(input('What is the resistance: '))) return resistance def calc(resistance): print(sum(resistance),' ohms') def_resistance=num() calc(def_resistance)

End Corona!

Brief: Create a function that takes the number of daily average recovered cases recovers, daily average new_cases, current active_cases, and returns the number of days it will take to reach zero cases.

import math as m def num(): recovers=int(input('Enter the amount on average recovered: ')) new_cases=int(input('Enter the amount of new cases on average daily: ')) active_cases=int(input('Enter the amount of active cases: ')) return recovers,new_cases,active_cases def calc(recovers,new_cases,active_cases): print(m.ceil(active_cases/(recovers - new_cases))) def_recovers,def_new_cases,def_active_cases=num() calc(def_recovers,def_new_cases,def_active_cases)

Brief:

Brief:

Brief:

Brief:

Brief:

Brief:

Brief:

Brief:

Brief: