#آموزش دستورات شرطی در پایتون
Condition in python
age = 12
name = 'ali'
language = 'python'
if age == 12:
print("age is 12")
#output : age is 12
if age is 12:
print("age is 12")
#output : age is 12
if age == 13:
print("ok")
else:
print("less than 13")
#output : less than 13
if age == 14:
print("age is 14")
elif age == 13:
print("age is 13")
elif age == 12:
print("age is 12")
if age is not 13:
print("age is not 13")
#output : age is not 13
if age >= 12:
print("ok")
#output : ok
if age <= 13:
print("ok")
#output : ok
if age != 12:
print("ok")
# مخالف ۱۲ نیستشage اجرا نمیشه چون
if name == 'ali' and age == 13:
print("welcome1")
#output : اجرا نمیشه چون شرط دوم برقرار نشده و شرط کلی اجرا نمیشه
if name == 'ali' or age == 13:
print("welcome")
#output : welcome
if name == 'ali' and (age == 14 or language == 'python'):
print("welcome")
#output : welcome
lst = [1, 2, 3 , 4]
if 1 in lst:
print("1 is in list")
#output : 1 is in list
if 6 not in lst:
print("6 is not in list")
#output : 6 is not in list
age = 14
name = "ali" if age < 12 else "mohammad"
print(name)
#output : mohammad
name = 'ali' if age < 15 else 'vali' if age > 15 else 'hasan'
print(name)
#output : ali
if age < 15:
if age > 15:
print('vali')
else:
print('ali')
else:
print('hasan')
#output : ali
name = (('vali', 'mohammad')[age > 12])
print(name)
#output : mohammad
name = (('vali', 'mohammad')[True])
print(name)
#output : mohammad
name = ('hasan', 'babak')[age < 12]
print(name)
#output : hasan
name = ('hasan', 'babak')[False]
#output : hasan
name = (age < 20) and 'ali' or 'hasan'
print(name)
#output : ali
name = {True: 'ali', False: 'hasan'}[age < 20]
print(name)
#output : ali
name = ((age > 20) and ['ali'] or ['hasan'])
print(name)
#output : ['hasan']
name = ((age > 20) and ['ali'] or ['hasan'])[0]
print(name)
#output : hasan
x = [True, True, False]
if any(x):
print("At least one True")
#output : At least one True
if all(x):
print("Not one False")
else:
print("At least one False")
#ouput : At least one False
if any(x) and not all(x):
print("At least one True and one False")
#output : At least one True and one False
با تشکر از مهندس
@milad_ghasemi_1
❇️ @raspberry_python
Condition in python
age = 12
name = 'ali'
language = 'python'
if age == 12:
print("age is 12")
#output : age is 12
if age is 12:
print("age is 12")
#output : age is 12
if age == 13:
print("ok")
else:
print("less than 13")
#output : less than 13
if age == 14:
print("age is 14")
elif age == 13:
print("age is 13")
elif age == 12:
print("age is 12")
if age is not 13:
print("age is not 13")
#output : age is not 13
if age >= 12:
print("ok")
#output : ok
if age <= 13:
print("ok")
#output : ok
if age != 12:
print("ok")
# مخالف ۱۲ نیستشage اجرا نمیشه چون
if name == 'ali' and age == 13:
print("welcome1")
#output : اجرا نمیشه چون شرط دوم برقرار نشده و شرط کلی اجرا نمیشه
if name == 'ali' or age == 13:
print("welcome")
#output : welcome
if name == 'ali' and (age == 14 or language == 'python'):
print("welcome")
#output : welcome
lst = [1, 2, 3 , 4]
if 1 in lst:
print("1 is in list")
#output : 1 is in list
if 6 not in lst:
print("6 is not in list")
#output : 6 is not in list
age = 14
name = "ali" if age < 12 else "mohammad"
print(name)
#output : mohammad
name = 'ali' if age < 15 else 'vali' if age > 15 else 'hasan'
print(name)
#output : ali
if age < 15:
if age > 15:
print('vali')
else:
print('ali')
else:
print('hasan')
#output : ali
name = (('vali', 'mohammad')[age > 12])
print(name)
#output : mohammad
name = (('vali', 'mohammad')[True])
print(name)
#output : mohammad
name = ('hasan', 'babak')[age < 12]
print(name)
#output : hasan
name = ('hasan', 'babak')[False]
#output : hasan
name = (age < 20) and 'ali' or 'hasan'
print(name)
#output : ali
name = {True: 'ali', False: 'hasan'}[age < 20]
print(name)
#output : ali
name = ((age > 20) and ['ali'] or ['hasan'])
print(name)
#output : ['hasan']
name = ((age > 20) and ['ali'] or ['hasan'])[0]
print(name)
#output : hasan
x = [True, True, False]
if any(x):
print("At least one True")
#output : At least one True
if all(x):
print("Not one False")
else:
print("At least one False")
#ouput : At least one False
if any(x) and not all(x):
print("At least one True and one False")
#output : At least one True and one False
با تشکر از مهندس
@milad_ghasemi_1
❇️ @raspberry_python
https://medium.com/conectric-networks/playing-with-raspberry-pi-traffic-lights-with-a-finite-state-machine-c6dc7035b8a1
🔰 @raspberry_python
🔰 @raspberry_python
Medium
Playing with Raspberry Pi: Traffic Lights with a Finite State Machine
This is the third article in our series where we’re playing with the Low Voltage Labs LED Traffic Lights using Python on the Raspberry Pi…
https://blog.hackster.io/protect-your-credit-card-by-building-a-skimmer-detector-with-a-raspberry-pi-f670f94ffcb2
🔰 @raspberry_python
🔰 @raspberry_python
Hackster.io
Protect Your Credit Card By Building a Skimmer Detector with a Raspberry Pi
Credit card skimmers are so effective because they’re very simple. Usually, they’re small modules that are connected to the magnetic stripe…
https://blog.hackster.io/the-zerophone-a-linux-smartphone-powered-by-the-raspberry-pi-zero-286f36a25fd4
🔰 @raspberry_python
🔰 @raspberry_python
Hackster.io
The ZeroPhone, a Linux Smartphone Powered by the Raspberry Pi Zero
We took a look at early prototypes of the ZeroPhone by Arsenij Pichugin back in January 2017 when the hardware was in a far less mature…
Forwarded from Micropython & IOT (F.Naserizadeh)
اندازه گیری سطح مایعات با آردینو
🔰 Arduino Liquid Level Sensor Circuit
const int sensorPin= 0;
int liquid_level;
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
}
void loop() {
liquid_level= analogRead(sensorPin);
Serial.println(liquid_level);
delay(100);
}
🔰 @micropython_iot
🔰 Arduino Liquid Level Sensor Circuit
const int sensorPin= 0;
int liquid_level;
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
}
void loop() {
liquid_level= analogRead(sensorPin);
Serial.println(liquid_level);
delay(100);
}
🔰 @micropython_iot
Forwarded from 🐍 Python & Raspberry 🐍 (F.Naserizadeh)
با عرض سلام خدمت اعضای محترم کانال
دوستانی که در محل کارشون نیاز به استخدام نفرات جدید دارند، در صورت تمایل میتوانند نیازمندی خودشونو به ما اعلام کنند.
تا جایی که بنده سراغ دارم.نفرات با استعداد و با رزومه خوب در حوزه های مختلف در این کانال حضور دارند.
دوستانی هم که دنبال کار هستند میتوانند رزومه خودشونو به آیدی زیر ارسال کنند.
@farhad3412
موفق باشید.🌺
این پست به جهت آن صورت میگیرد که موارد از این دست بارها برای ما فرستاده شده است.
و انشاءالله که بتوان این ارتباط را برقرار کرد.
دوستانی که در محل کارشون نیاز به استخدام نفرات جدید دارند، در صورت تمایل میتوانند نیازمندی خودشونو به ما اعلام کنند.
تا جایی که بنده سراغ دارم.نفرات با استعداد و با رزومه خوب در حوزه های مختلف در این کانال حضور دارند.
دوستانی هم که دنبال کار هستند میتوانند رزومه خودشونو به آیدی زیر ارسال کنند.
@farhad3412
موفق باشید.🌺
این پست به جهت آن صورت میگیرد که موارد از این دست بارها برای ما فرستاده شده است.
و انشاءالله که بتوان این ارتباط را برقرار کرد.