Python – die besten Beiträge

Primzahlengenerator: Ist die Funktion, die ich in Python programmiert bereits bekannt?

Im folgenden Python Programm werden alle ungeraden Primzahlen generiert.

Es verwendet die senkrechte "Mittellinie" des Pascalschen Dreiecks. Beispielzahlen, die verwendet werden: 2,6,20,70,252,924,3432,.....

2 \ 3 = 2 -> 3 - 2 = 1 -> Prim
6 \ 5 = 1 -> Prim
20 \ 7 = 6 -> 7 - 6 = 1 -> Prim
70 \ 9 = 7 bzw. 9 - 7 = 2 -> Rest ungleich 1 -> nicht Prim
252 \ 11 = 10 -> 11 - 10 = 1 -> Prim
# Programer: Peter Rasinger, Ferlach, Austria, 2005 - 2021
import math
import decimal
decimal.getcontext().prec = 2500000 #250000000000000000
decimal.getcontext()
def is_prim(a4,d4):
  f4 = a4 % d4
  g4 = d4 - f4
  if f4 == 1 or g4 == 1 and d4 != 1:
    return(1==1)
  else:
    return(1==2)
def calc_prim(f3,g3,h3): #f3 = x over x/2 : x \ 2 == 0 ... and g3 == x / 2 ... 6 over 3 = 20 = 6! / (3! * 3!), 8 over 4 = 70
             #h3 = steps to calulate (impair numbers)
  a3 = f3
  b3 = g3
  c3 = b3 + 1
  if is_prim(a3,c3):
    print(c3)
  for i3 in range(g3 + 2,(h3 * 2) + g3,2):
    r3 = a3 * 4
    s3 = r3 // i3
    a3 = r3 - s3
    b3 = i3
    c3 = b3 + 1
    if is_prim(a3,c3):
      print(c3)
  print(math.trunc((math.log(a3) // math.log(10)) + 1)," max digits used")
calc_prim(252,10,100) #252 = 10! / (5! * 5!) ... check 100 impairs ... startvalues for 11
#calc_prim(924,12,100) #924 = 12! / (6! * 6!) ......................... startvalues for 13
#calc_prim(2,2,5)
Mathematik, programmieren, Primzahlen, Python

Python "in" in einer IF-verzweigen funktioniert nicht?

Hallo zusammen,

ich möchte per Tastendruck den Link zu einem Screenshot z.B. https://i.imgur.com/qk5TpU0.png
aus meiner Zwischenablage in ein Google Spreadshead hochladen. Diese sollen natürlich untereinander erscheinen und nicht doppelt. Hier funktioniert aber nicht der "in" Operator.

Bild vom Spreadshead: https://i.imgur.com/gOxxDeN.png

Der Code: "
import keyboard
from tkinter import Tk
import gspread
from oauth2client.service_account import ServiceAccountCredentials

# use creds to create a client to interact with the Google Drive API
scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
         "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)

# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("test für api").sheet1


def check_value_existence():
    row = 2  # Reihe
    col = 2  # Spalte
    value = sheet.cell(col, row).value
    clipboard = Tk().clipboard_get()
    if "imgur" in value:
        while True:
            col = col + 1
            value = sheet.cell(col, row).value
            if "imgur" in value:
                break
        print("found", col)
        col = col - 1
        if value != clipboard:
            sheet.update_cell(2, 2, clipboard)


while True:
    if keyboard.read_key() == "p":
        print("You pressed p")
        check_value_existence()
"
Computer, programmieren, Code, Informatik, Python, Python 3

Meistgelesene Beiträge zum Thema Python