samedi 27 mars 2021

Mean from a list with a condition in Python

list = [[159.2213, 222.2223, 101.2122]
        [359.2222, 22.2210, 301.2144]]

if list[1][0] < list[0][0]:
    avg = (list[1][0] + list[0][0] - 200)/2
else:
    avg = (list[1][0] + list[0][0] + 200)/2

Hello! I want to do this for every column and output the results in another list.

How to use If with listBox1.SelectedItem to change a picture box

So I want a Listbox and when u press an element in the list box the picture box changes the picture so i have 4 picture boxes behind each other and I want to do

If listBox1.SelectedItem "Flowers" Then
pictureBox1.Show():
pictureBox2.Hide();
pictureBox3.Hide();

but iI keep getting an error I can't use if with selected item help

im using c# winfroms .net frameworks

How to find the longest English Word that can be displayed in a seven segment display?

I was inspired from Tom Scott's Video about seven segment displays (link Below), and set out to find out the longest english word that can be displayed in a seven segment display using python, I am a beginner and the best code I could write was this:

var1=open("c:/Users/Choutisha Banerjee/Desktop/words.txt", "r")
list1=var1.readlines()
list2 = ["g","k","m","q","v","w","x","z"]
longword=" "
for n in list1:
    if len(n)>len(longword):
        for x in n:
         if x in list2:
             continue
    else:
         longword=n
else:
    continue
print(longword)

It is printing the longest word present in the list. It would be a great help if you could inform me about where I went wrong.

(I used a premade list of all english words i.e. words.txt)

Link to Tom's Video: https://youtu.be/zp4BMR88260

link to .py (just in case you need it): https://drive.google.com/file/d/1M78YP67VkqC2Uz3mbQxcqk15vO7mW6Rx/view?usp=sharing

Please Help Thank you.

If statement with Match function in vba

I'm working on collection database, that can be used for sport cards. I'm nearly done with everything, but I have a problem with Match function in VBA. I tried to combine it with If statement, but if the Match function does not giving back a result, then the macro stops. Here is this part of the code:

Dim shortnamee As Integer
Dim ittkeres As Range
    Set ittkeres = Range("X:X") 
    shortnamee = WorksheetFunction.Match(Range("V2"), ittkeres, 0)
    Range("V3") = shortnamee
    If Range("V3").Value > 0 Then

This part connects to the first page, where I can add new items to the collection sheets, and here it looks for duplicates from a concatenated name (V2 - the new items name; X:X - where the rest of the collection is, already uploaded. Thanks a lot!

How to continue python programme when a webpage is not reachable

Hello Stackoverflow members, I am very new to python hence i need a little bit of help with this small dilemma i have come across, what needs to be done is: if 10.10.10.2 is reachable the programm should exit() but if 10.10.10.2 is not reachable in 10 seconds 192.168.100.5 will be opened and the programm will continue... If anyone could give a small example as to how that could be done it would be much appreciated.

import requests
import urllib.request
import eventlet
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
from xml.dom import minidom
import urllib.request
import time

preflash = urllib.request.urlopen("http://10.10.10.2").getcode()
correct = urllib.request.urlopen("http://192.168.100.5").getcode()

print(100*"#")

#eventlet.monkey_patch()
#with eventlet.Timeout(10):

if True:
         print("Web page status code:",preflash)
         print("Web page is reachable")

else:    
    print("Web page status code:", correct)
    print("Web page is reachable")
url_str = 'http://192.168.100.2/globals.xml'

# open webpage and read values
xml_str = urllib.request.urlopen(url_str).read()

# Parses XML doc to String for Terminal output
xmldoc = minidom.parseString(xml_str)

# Finding the neccassary Set points/ Sollwerte from the xmldoc

# prints the order_number from the xmldoc
order_number = xmldoc.getElementsByTagName('order_number')
print("The Order number of the current device is:", order_number[0].firstChild.nodeValue)
print(100*"-") 

If-Else condition not getting detected in Google Apps Script

I am looping over the list "res_1" and when the Id is "400" then need to multiply "Total_Weight" with variable "cost_400"; else if the id is "400W", then need to multiply "Total_Weight" with variable "cost_400W". In the end, "result" array should contain "Vendor" and correspoding number ("Total_Weight" * "cost_400").

In the code below, I loop over "res_1", but for some reason, the if condition is not getting detected and it does not go inside the corresponding if or else if condition. Any suggestions would be appreciated.

Expected result:

result = [['ABC',42341820 ],['DEF',91734000]]

Input:

res_1:

[ { Id: '400 ', Vendor: 'ABC', Total_Weight: 32322 },
  { Id: '400W ', Vendor: 'DEF', Total_Weight: 61156 } ]

var cost_400 = 1310
var cost_400W = 1500

res_1.forEach((r2,i2)=>{
  if (r2['Id'] == "400" ) {
    Logger.log(r2['Total_Weight']*cost_400)
  }
  else if (r2['Id'] == "400W" ) {
    Logger.log(r2['Total_Weight']*cost_400W)
  }
});

how to make 'B', 'C' codes are not to be loaded into memory to improve performance when 'A' is chosen among 'A', 'B', 'C' through if else?

Let's say we have car management software and codes are,

if (power== "gasoline")
{
   // many code
}
else if (power== "diesel")
{
   // many code
}
else if (power== "electric")
{
   // many code 
}
else if (power== "hybrid")
{
   // many code
}

As title of this question, I don't want the code of 'diesel', 'electric', 'hybrid' to be loaded into memory to improve performance when a user selects 'gasoline'.

Is there a excellent way for this case ?

Thank you !