DR - Racket Tutorial 2
DR - Racket Tutorial 2
Implement solutions for the following scenarios using DrRacket and Python.
1) Design a program to calculate the length of a given string and return the phrase “The
total number of characters in the string is..[answer]”.
Dr.Racket
(define (calculate-length string)
Python
def calculate_length (string):
return (len(string))
Dr.Racket
(define (area-of-ring outer inner)
(- (area-of-disk outer)
(area-of-disk inner)))
(define (area-of-disk r)
(* pi r r))
Python
def circle_area (radius):
pi = 22/7
return pi*radius*radius
print(ring_area(5,3))
3) Calculate the value of b2-4ac for the quadratic formula ax2+bx+c=0, when provided a, b,
c variable values as parameters.
Design the program to give command line inputs as well.
Dr.Racket
(define (roots a b c)
(- (* b b) (* 4 a c))
(- (* b b) (* 4 a c))
Python
def roots(a,b,c):
print(roots(3,2,1))