-3

Hello guys this is my program :

GNU nano 2.7.4                                                                                                  
File : com.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import serial
import time
import sys

ser = serial.Serial('/dev/ttyACM0', 9600)
time.sleep(4)

while True:     
  mdp = raw_input("Enter Number :")
  print mdp
  ser.write(mdp)
  print(ser.readline())
  time.sleep(1)

When i execute it i get those number 15.80-14-18.00-14.24 and i want to use each number in different variables like :

var1=15.80
var2=14
var3=18.00
var4=14.24

Thank you for taking time to read my question.

Edit: thanks for your answer

14.50-14-19.30-3.34

14.50
14
19.30
3.34

Enter Number: 5
5
14.50-14-19.30-3.34

Traceback (most recent call last):
File "com.py", line 15, in <module>
var1,var2,var3,var4 = var0.split("-")

i had a problem with the serial connection i want to test "var0" and know if it has 4 value or not

TS2IR 2018
  • 27
  • 3

1 Answers1

-2

This could be one way to achieve this

var0 = "15.80-14-18.00-14.24"

you could do something like this

var1,var2,var3,var4 = var0.split("-")
CodeCupboard
  • 1,507
  • 3
  • 17
  • 26