Difference between revisions of "Coursera Google Python Automation Course"

From rbachwiki
Jump to navigation Jump to search
(Created page with "==If statements== <pre> def convert_distance(dist, unit): # if(unit =="mile"): xtext=" The distance is " ml = dist / 1.6 m...")
 
 
(One intermediate revision by the same user not shown)
Line 22: Line 22:
print(str(xme))
print(str(xme))
</pre>
</pre>
==[[#top|Back To Top]] - [[Python|Category]]==
[[Category:Python]]

Latest revision as of 16:21, 1 September 2020

If statements


def convert_distance(dist, unit):
    #
        	if(unit =="mile"):
        	    xtext=" The distance is "
        	    ml = dist / 1.6
        	    mlr = int(ml)
        	    output = xtext + str(mlr) + " " + unit
        	    return output
        	    
        	elif(unit=="km"):
        	    xtext=" is "
        	    km = dist * 1.6 
        	    kmr = int(km)
        	    output = str(dist) + " Miles" + xtext + str(kmr) + " " + unit
        	    return output


xme = convert_distance(100, "km")
print(str(xme))

Back To Top - Category