Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- a function that accepts the dimensions of a triangle and returns its area.
- """
- height=int(input("Please enter the dimension corresponding to the height of your triangle: "))
- base=int(input("Please enter the dimension corresponding to the base of your triangle: "))
- def area_triangle(a,b):
- area=0.5*height*base
- return area
- areaoftriangle=area_triangle(height,base)
- print(areaoftriangle)
- """
- a function that accepts a string and returns the same string reversed.
- """
- string=input("Enter your string: ")
- def reversed_string(string):
- reversed=string[::-1]#Reversing a string starting from last position to first position and move backward by one step.
- return reversed
- reversed_str=reversed_string(string)
- print(reversed_str)
- """
- a function that simulates a pair of dice being rolled n times and returns
- the number of occurrences of each score.
- """
- import random
- n=int(input("how many times you need to roll your dice? "))
- def dice(n):
- rolls = []
- for i in range(n):
- two_dice = random.randint(1, 6) , random.randint(1, 6)#list comprehension
- rolls.append(two_dice)
- occurrence = {score: rolls.count(score)for score in rolls}#counting elements in a list using count()
- return occurrence
- print(dice(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement