Python Forum
simple if elif conditions in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple if elif conditions in Python
#1
Hi There,
I am very much new to Python and to this forum. I am looking for code help.
I have a SAS code as below and I would like to replicate this in Python.
It would be great if you guys can assist me with this.

if Universtiy in ("name1","name2","name3") then Universtiy_Group='Go8 University';
else if University in ("name4","name5") then Universtiy_Group='Eligible Go8 University';
else Universtiy_Group="Others";

Kind regards,
CK
Reply
#2
if Universtiy in ("name1","name2","name3"):
    Universtiy_Group = 'Go8 University'
elif University in ("name4","name5"):
    Universtiy_Group = 'Eligible Go8 University'
else:
    Universtiy_Group = "Others"
Note the indentation. While indentation is ignored by SAS, it is part of the syntax in Python.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
university = "name1"

if university in ("name1", "name2", "name3"):
    university_group = "Go8 University"
elif university in ("name4","name5"):
    university_group = "Eligible Go8 University"
else:
    university_group = "Others"
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python uppercase conversion conditions Jaypeng 7 2,893 Apr-29-2020, 11:24 AM
Last Post: jefsummers
  python ast if-elif confusion holyghost 3 3,017 Apr-19-2020, 12:36 PM
Last Post: pyzyx3qwerty
  How does while-If-elif-else-If loop conditions check run mrhopeedu 2 1,749 Oct-27-2019, 04:56 AM
Last Post: mrhopeedu
  Python coding mutiple elif's metro17 1 1,741 Aug-02-2019, 10:27 AM
Last Post: metulburr
  Whats the right way to refactor this Big if/elif/elif ? pitosalas 1 2,214 Jul-28-2019, 05:52 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020