Open main menu

Biolecture.org β

Changes

Regular Expressions

703 bytes added, 02:42, 3 December 2018
Created page with "<pre> import sys import re while True: my_degree=input("Enter a degree:") cond1=".[c]" cond2 = ' .[f]' regexp1 = re/compile(cond1, re..."
<pre>
import sys
import re
while True:
my_degree=input(&quot;Enter a degree:&quot;)
cond1=&quot;.[c]&quot;
cond2 = &#39; .[f]&#39;

regexp1 = re/compile(cond1, re.IGNORECASE)
result = regexp1.search(my_degree)

regexp2 = re.compile(cond2, re.IGNORECASE)
result2 = regexp2.search(my_degree)

if result1 :
degree = float(my_degree[0:len(my_degree)-1])
f = (9/5)*degree+32
print(&#39;%0.2f&#39;%f, &#39;F&#39;, sep=&#39;&#39;)
break
elif result2 :
degree = float(my_degree[0:len(my_degree)-1])
c= (5/9)*degree-32
print(&#39;%0.2f&#39;%f, &#39;C&#39;, sep=&#39;&#39;)
break
else:
continue</pre>
Anonymous user