Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,970 questions

51,912 answers

573 users

How to use assertion in Python

2 Answers

0 votes
celsius = -2

fahrenheit = ((9.0 / 5.0) * celsius) + 32

print(fahrenheit) 
print(fahrenheit <= 30) 

assert fahrenheit >= 30, "It's very cold" # if false

print("Temperature in Fahrenheit =", fahrenheit)




'''
run:

28.4
True
Traceback (most recent call last):
  File "<string>", line 8, in <module>
AssertionError: It's very cold

'''

 



answered Oct 6, 2021 by avibootz
0 votes
assert 2 + 2 == 4, "true"

assert 2 + 2 == 5, "false"





'''
run:

Traceback (most recent call last):
  File "<string>", line 3, in <module>
AssertionError: false

'''

 



answered Oct 6, 2021 by avibootz

Related questions

1 answer 102 views
102 views asked Sep 23, 2021 by avibootz
1 answer 183 views
6 answers 391 views
2 answers 138 views
...